Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: e2e cucumber import #291

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions integration-tests/e2e-tests/src/abilities/WalletSdk.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Ability, Discardable, Initialisable, Interaction, Question, QuestionAdapter } from "@serenity-js/core"
import SDK from "@hyperledger/identus-edge-agent-sdk"
import type SDK from "@hyperledger/identus-edge-agent-sdk"
import axios from "axios"
import { CloudAgentConfiguration } from "../configuration/CloudAgentConfiguration"
import InMemoryStore from "../configuration/inmemory"
import { randomUUID, UUID } from "crypto"


let instance: typeof import("@hyperledger/identus-edge-agent-sdk").default;
// fallback in any case of dangling sdk agents
export const agentList: Map<string, WalletSdk> = new Map()

Expand All @@ -15,6 +15,8 @@ export class WalletSdk extends Ability implements Initialisable, Discardable {
messages: MessageQueue = new MessageQueue()
id: UUID = randomUUID()



static async withANewInstance(): Promise<Ability> {
return new WalletSdk()
}
Expand Down Expand Up @@ -75,6 +77,11 @@ export class WalletSdk extends Ability implements Initialisable, Discardable {
})
}

static async loadSDK() {
instance ??= require("@hyperledger/identus-edge-agent-sdk");
elribonazo marked this conversation as resolved.
Show resolved Hide resolved
return instance
}

async discard(): Promise<void> {
agentList.delete(this.id)
if (this.isInitialised()) {
Expand All @@ -84,22 +91,29 @@ export class WalletSdk extends Ability implements Initialisable, Discardable {
}

async createSdk(seed: SDK.Domain.Seed = undefined) {
const { Agent, Apollo, Domain, ListenerKey, } = SDK
const {
Agent,
Apollo,
Domain,
ListenerKey,
Store,
Pluto
} = await WalletSdk.loadSDK()
const apollo = new Apollo()
this.store = new SDK.Store({
this.store = new Store({
name: [...Array(30)].map(() => Math.random().toString(36)[2]).join(""),
storage: InMemoryStore,
password: "random12434",
ignoreDuplicate: true
})
const pluto = new SDK.Pluto(this.store, apollo)
const pluto = new Pluto(this.store, apollo)
const mediatorDID = Domain.DID.fromString(await WalletSdk.getMediatorDidThroughOob())
this.sdk = Agent.initialize({ seed, apollo, pluto, mediatorDID })

this.sdk.addListener(
ListenerKey.MESSAGE, (messages: SDK.Domain.Message[]) => {
ListenerKey.MESSAGE, async (messages: SDK.Domain.Message[]) => {
for (const message of messages) {
this.messages.enqueue(message)
await this.messages.enqueue(message)
}
}
)
Expand Down Expand Up @@ -139,12 +153,12 @@ class MessageQueue {

receivedMessages: string[] = []

enqueue(message: SDK.Domain.Message) {
async enqueue(message: SDK.Domain.Message) {
this.queue.push(message)

// auto start processing messages
if (!this.processingId) {
this.processMessages()
await this.processMessages()
}
}

Expand All @@ -162,7 +176,8 @@ class MessageQueue {
return this.queue.length
}

processMessages() {
async processMessages() {
const SDK = await WalletSdk.loadSDK();
this.processingId = setInterval(() => {
if (!this.isEmpty()) {
const message: SDK.Domain.Message = this.dequeue()
Expand All @@ -175,7 +190,6 @@ class MessageQueue {

this.receivedMessages.push(message.id)


if (piUri === SDK.ProtocolType.DidcommOfferCredential) {
this.credentialOfferStack.push(message)
} else if (piUri === SDK.ProtocolType.DidcommRequestPresentation) {
Expand Down
3 changes: 2 additions & 1 deletion integration-tests/e2e-tests/src/steps/EdgeAgentSteps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Actor, Notepad } from "@serenity-js/core"
import { EdgeAgentWorkflow } from "../workflow/EdgeAgentWorkflow"
import { CloudAgentWorkflow } from "../workflow/CloudAgentWorkflow"
import { Utils } from "../Utils"
import SDK from "@hyperledger/identus-edge-agent-sdk"

Given("{actor} has '{int}' jwt credentials issued by {actor}",
async function (edgeAgent: Actor, numberOfIssuedCredentials: number, cloudAgent: Actor) {
Expand Down Expand Up @@ -180,6 +179,7 @@ Then("{actor} is dismissed",

Then("{actor} will request {actor} to verify the anonymous credential",
async function (verifierEdgeAgent: Actor, holderEdgeAgent: Actor) {
const SDK = await EdgeAgentWorkflow.instance;
await EdgeAgentWorkflow.createPeerDids(holderEdgeAgent, 1)
const holderDID = await holderEdgeAgent.answer(Notepad.notes().get("lastPeerDID"))
const claims = {
Expand All @@ -197,6 +197,7 @@ Then("{actor} will request {actor} to verify the anonymous credential",

Then("{actor} will request {actor} to verify the JWT credential",
async function (verifierEdgeAgent: Actor, holderEdgeAgent: Actor) {
const SDK = await EdgeAgentWorkflow.instance;
await EdgeAgentWorkflow.createPeerDids(holderEdgeAgent, 1)
const holderDID = await holderEdgeAgent.answer(Notepad.notes().get("lastPeerDID"))
const claims = {
Expand Down
18 changes: 11 additions & 7 deletions integration-tests/e2e-tests/src/workflow/EdgeAgentWorkflow.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SDK from "@hyperledger/identus-edge-agent-sdk"
import type SDK from "@hyperledger/identus-edge-agent-sdk"
import { Actor, Duration, Notepad, TakeNotes, Wait } from "@serenity-js/core"
import { Ensure, equals } from "@serenity-js/assertions"
import { WalletSdk } from "../abilities/WalletSdk"
Expand All @@ -9,6 +9,9 @@ import { assert } from "chai"


export class EdgeAgentWorkflow {
static get instance() {
return WalletSdk.loadSDK()
}

static async connect(edgeAgent: Actor) {
const url = await edgeAgent.answer<string>(Notepad.notes().get("invitation"))
Expand Down Expand Up @@ -39,7 +42,7 @@ export class EdgeAgentWorkflow {
}

static async processIssuedCredential(edgeAgent: Actor, recordId: string) {
const { IssueCredential } = SDK;
const { IssueCredential } = await this.instance;
await edgeAgent.attemptsTo(
WalletSdk.execute(async (sdk, messages) => {
const issuedCredential = messages.issuedCredentialStack.shift()!
Expand All @@ -51,7 +54,7 @@ export class EdgeAgentWorkflow {
}

static async acceptCredential(edgeAgent: Actor) {
const { OfferCredential } = SDK
const { OfferCredential } = await this.instance;

await edgeAgent.attemptsTo(
WalletSdk.execute(async (sdk, messages) => {
Expand All @@ -77,7 +80,7 @@ export class EdgeAgentWorkflow {
}

static async presentVerificationRequest(edgeAgent: Actor) {
const { RequestPresentation } = SDK
const { RequestPresentation } = await this.instance;

await edgeAgent.attemptsTo(
WalletSdk.execute(async (sdk, messages) => {
Expand All @@ -100,7 +103,7 @@ export class EdgeAgentWorkflow {
}

static async verifyPresentation(edgeAgent: Actor, expected: boolean = true) {
const { Presentation } = SDK
const { Presentation } = await this.instance;

await edgeAgent.attemptsTo(
WalletSdk.execute(async (sdk, messages) => {
Expand All @@ -123,7 +126,7 @@ export class EdgeAgentWorkflow {
}

static async tryToPresentVerificationRequestWithWrongAnoncred(edgeAgent: Actor) {
const { RequestPresentation } = SDK
const { RequestPresentation } = await this.instance;
await edgeAgent.attemptsTo(
WalletSdk.execute(async (sdk, messages) => {
const credentials = await sdk.verifiableCredentials()
Expand All @@ -142,7 +145,7 @@ export class EdgeAgentWorkflow {
}

static async presentProof(edgeAgent: Actor) {
const { RequestPresentation } = SDK
const { RequestPresentation } = await this.instance;

await edgeAgent.attemptsTo(
WalletSdk.execute(async (sdk, messages) => {
Expand Down Expand Up @@ -301,6 +304,7 @@ export class EdgeAgentWorkflow {
}

static async createNewWalletFromBackupWithWrongSeed(edgeAgent: Actor) {
const SDK = await this.instance;
const backup = await edgeAgent.answer(Notepad.notes().get("backup"))
const walletSdk = new WalletSdk()
const seed = new SDK.Apollo().createRandomSeed().seed
Expand Down
4 changes: 2 additions & 2 deletions src/mercury/didcomm/Wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Attachment,
AttachmentData,
} from "didcomm-wasm";
import wasmBuffer from "../../../externals/generated/didcomm-wasm/didcomm_js_bg.wasm"
import wasmBuffer from "didcomm-wasm/didcomm_js_bg.wasm"

import * as Domain from "../../domain";
import { DIDCommDIDResolver } from "./DIDResolver";
Expand All @@ -34,11 +34,11 @@

public static async getDIDComm() {
this.didcomm ??= await import("didcomm-wasm").then(async module => {
const wasmInstance = module.initSync(wasmBuffer);
const wasmInstance = module.initSync({ module: wasmBuffer });
await module.default(wasmInstance);
return module;
});
return this.didcomm!;

Check warning on line 41 in src/mercury/didcomm/Wrapper.ts

View workflow job for this annotation

GitHub Actions / Build and test

Forbidden non-null assertion
}

private doesRequireReturnRoute(type: string) {
Expand Down
17 changes: 5 additions & 12 deletions src/pollux/AnoncredsLoader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// import { Anoncreds } from "../domain/models/Anoncreds";
import type * as Anoncreds from "anoncreds-wasm";



import wasmBuffer from 'anoncreds-wasm/anoncreds_wasm_bg.wasm';
/**
* @class AnoncredsLoader
* handle loading and access of anoncreds library
Expand All @@ -21,18 +24,8 @@ export class AnoncredsLoader {

private async load() {
this.pkg ??= await import("anoncreds-wasm").then(async module => {

let wasmBuffer: Buffer;
if (typeof window !== 'undefined') {
const wasmModule = await import("../../externals/generated/anoncreds-wasm/anoncreds_wasm_bg.wasm")
wasmBuffer = wasmModule.default as any
module.initSync(wasmBuffer);

} else {
const wasmModule = await import("../../externals/generated/anoncreds-wasm/anoncreds_wasm_bg.wasm")
wasmBuffer = wasmModule.default as any
module.initSync(wasmBuffer);
}
const wasmInstance = module.initSync({ module: wasmBuffer });
await module.default(wasmInstance);
return module
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/pollux/Pollux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
if (jwsArray.length !== 3) {
throw new PolluxError.InvalidJWTString("Credential status jwt is invalid")
}
const { proof, ...cleanedPayload } = revocation;

Check warning on line 262 in src/pollux/Pollux.ts

View workflow job for this annotation

GitHub Actions / Build and test

'proof' is assigned a value but never used. Allowed unused vars must match /^_/u
const payload = { ...cleanedPayload };
const encoded = await this.encode(payload)
const signature = Buffer.from(base64url.baseDecode(jwsArray[2]));
Expand Down Expand Up @@ -838,7 +838,7 @@
async start() {
this._anoncreds = await AnoncredsLoader.getInstance();
this._jwe ??= await import("jwe-wasm").then(async module => {
const wasmInstance = module.initSync(wasmBuffer);
const wasmInstance = module.initSync({ module: wasmBuffer });
await module.default(wasmInstance);
return module;
});
Expand Down
Loading