Skip to content

Commit

Permalink
wip2
Browse files Browse the repository at this point in the history
Signed-off-by: Curtish <[email protected]>
  • Loading branch information
curtis-h committed Jan 15, 2025
1 parent d970d47 commit ffe2e9c
Show file tree
Hide file tree
Showing 90 changed files with 4,151 additions and 910 deletions.
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"comma-dangle": 0,
"no-unexpected-multiline": "warn",
"prefer-const": "warn",
"@typescript-eslint/ban-types": "warn",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off",
Expand Down
5 changes: 3 additions & 2 deletions integration-tests/e2e-tests/src/abilities/WalletSdk.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Ability, Discardable, Initialisable, Interaction, Question, QuestionAdapter } from "@serenity-js/core"
import type SDK from "@hyperledger/identus-edge-agent-sdk"
import SDK from "@hyperledger/identus-edge-agent-sdk"
import axios from "axios"
import { axiosInstance, CloudAgentConfiguration } from "../configuration/CloudAgentConfiguration"
import InMemoryStore from "../configuration/inmemory"
Expand Down Expand Up @@ -173,7 +173,8 @@ export class WalletSdk extends Ability implements Initialisable, Discardable {
pluto,
mediatorDID,
castor
})
});
this.sdk.plugins.register(SDK.Plugins.Anoncreds);

this.sdk.addListener(
ListenerKey.MESSAGE, async (messages: SDK.Domain.Message[]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import {
} from "@amagyar-iohk/identus-cloud-agent-client-ts"
import { CloudAgentConfiguration } from "../configuration/CloudAgentConfiguration"
import { Utils } from "../Utils"
import SDK from "@hyperledger/identus-edge-agent-sdk"
import { JWTRevocationStatus } from "@hyperledger/identus-edge-agent-sdk/build/domain"

export class CloudAgentWorkflow {
static async createConnection(cloudAgent: Actor, label?: string, goalCode?: string, goal?: string) {
Expand Down Expand Up @@ -306,7 +304,7 @@ export class CloudAgentWorkflow {
const credentialResponse = await this.getCredential(cloudAgent, recordId)
const jwtString = Utils.decodeBase64URL(credentialResponse.credential)
const decoded = CloudAgentWorkflow.instance.JWTCredential.fromJWS(jwtString)
const credentialStatus = decoded.vc.credentialStatus as JWTRevocationStatus
const credentialStatus = decoded.vc.credentialStatus as any
const statusList = credentialStatus.statusListCredential
statusRegistry.set(recordId, statusList)
}
Expand Down
34 changes: 15 additions & 19 deletions integration-tests/node/assertions.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const runTests = (describe, test, assert, SDK) => {
assert("Domain" in SDK);
assert("Mercury" in SDK);
assert("Pluto" in SDK);
assert("Pollux" in SDK);

// misc modules
assert("ApiImpl" in SDK);
Expand Down Expand Up @@ -64,9 +63,6 @@ const runTests = (describe, test, assert, SDK) => {

// ?? should be in Pluto
assert("Store" in SDK);

// ?? shouldnt be exported
assert("isPresentationDefinitionRequestType" in SDK);
});

describe("Modules", () => {
Expand Down Expand Up @@ -126,21 +122,21 @@ const runTests = (describe, test, assert, SDK) => {
});
});

describe("Pollux", () => {
test("instantiates", async () => {
const apollo = new SDK.Apollo();
const castor = new SDK.Castor(apollo);
const pollux = new SDK.Pollux(apollo, castor);
assert(pollux instanceof SDK.Pollux);
assert(pollux.revealCredentialFields instanceof Function);
assert(pollux.isCredentialRevoked instanceof Function);
assert(pollux.parseCredential instanceof Function);
assert(pollux.processCredentialOffer instanceof Function);
assert(pollux.createPresentationSubmission instanceof Function);
assert(pollux.verifyPresentationSubmission instanceof Function);
assert(pollux.createPresentationDefinitionRequest instanceof Function);
});
});
// describe("Pollux", () => {
// test("instantiates", async () => {
// const apollo = new SDK.Apollo();
// const castor = new SDK.Castor(apollo);
// const pollux = new SDK.Pollux(apollo, castor);
// assert(pollux instanceof SDK.Pollux);
// assert(pollux.revealCredentialFields instanceof Function);
// assert(pollux.isCredentialRevoked instanceof Function);
// assert(pollux.parseCredential instanceof Function);
// assert(pollux.processCredentialOffer instanceof Function);
// assert(pollux.createPresentationSubmission instanceof Function);
// assert(pollux.verifyPresentationSubmission instanceof Function);
// assert(pollux.createPresentationDefinitionRequest instanceof Function);
// });
// });
});

test("Agent starts", async () => {
Expand Down
24 changes: 0 additions & 24 deletions src/domain/buildingBlocks/Pollux.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/domain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ export * from "./buildingBlocks/Apollo";
export * from "./buildingBlocks/Castor";
export * from "./buildingBlocks/Mercury";
export * from "./buildingBlocks/Pluto";
export * from "./buildingBlocks/Pollux";
export * from "./utils/JWT";
4 changes: 2 additions & 2 deletions src/domain/models/VerifiableCredential.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// TODO remove this when removing fn from Agent
import { OEA } from "../../pollux/plugins/oea/types";
import { Claims as ACClaims } from "../../pollux/plugins/anoncreds/types";
import { OEA } from "../../plugins/internal/oea/types";
import { Claims as ACClaims } from "../../plugins/internal/anoncreds/types";

export type PresentationClaims<T extends CredentialType = CredentialType.JWT> =
T extends CredentialType.JWT ? OEA.JWTPresentationClaims :
Expand Down
2 changes: 1 addition & 1 deletion src/domain/protocols/Payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export interface Payload {
}

export namespace Payload {
export const make = (pid: string, data: any) => ({ pid, data });
export const make = (pid: string, data: any): Payload => ({ pid, data });
}
42 changes: 18 additions & 24 deletions src/edge-agent/Agent.Backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@ import jweWasm from "jwe-wasm/jwe_rust_bg.wasm";
import * as Domain from "../domain";
import Agent from "./Agent";
import { Version } from "../domain/backup";
// import { isObject, validateSafe } from "../utils";
// import * as Domain from "../domain";
// import Agent from "./Agent";
import { isNil, isObject, notNil, validateSafe } from "../utils";


/**
* define Agent requirements for Backup
*/
// type BackupAgent = Pick<Agent, "apollo" | "pluto" | "pollux" | "seed">;
type BackupAgent = Pick<Agent, "apollo" | "pluto" | "seed">;
type BackupExclude = "messages" | "mediators" | "link_secret";

type MasterKey = Domain.PrivateKey & Domain.ExportableKey.Common & Domain.ExportableKey.JWK & Domain.ExportableKey.PEM;

export type BackupOptions = {
Expand All @@ -33,23 +28,22 @@ export class AgentBackup {
) {}

/**
* Creates a JWE (JSON Web Encryption) containing the backup data stored in Pluto.
* The data can optionally be encrypted using a custom master key, compressed,
* and filtered to exclude specified fields.
*
* @param {BackupOptions} [options] - Optional settings for the backup.
* @param {Version} [options.version] - Specifies the version of the backup data.
* @param {MasterKey} [options.key] - Custom master key used for encrypting the backup.
* @param {boolean} [options.compress] - If true, compresses the JWE using DEFLATE.
* @param {BackupExclude[]} [options.excludes] - Keys to exclude from the backup data
* (e.g., "messages", "mediators", "link_secret"). Arrays are cleared, and strings are set to empty strings.
*
* @returns {Promise<string>} - A promise that resolves to the JWE string.
*
* @see restore - Method to restore data from a JWE string.
*/
* Creates a JWE (JSON Web Encryption) containing the backup data stored in Pluto.
* The data can optionally be encrypted using a custom master key, compressed,
* and filtered to exclude specified fields.
*
* @param {BackupOptions} [options] - Optional settings for the backup.
* @param {Version} [options.version] - Specifies the version of the backup data.
* @param {MasterKey} [options.key] - Custom master key used for encrypting the backup.
* @param {boolean} [options.compress] - If true, compresses the JWE using DEFLATE.
* @param {BackupExclude[]} [options.excludes] - Keys to exclude from the backup data
* (e.g., "messages", "mediators", "link_secret"). Arrays are cleared, and strings are set to empty strings.
*
* @returns {Promise<string>} - A promise that resolves to the JWE string.
*
* @see restore - Method to restore data from a JWE string.
*/
async createJWE(options?: BackupOptions): Promise<string> {
// const backup = await this.Agent.pluto.backup();
let backup = await this.Agent.pluto.backup(options?.version);

if (options?.excludes && Array.isArray(options.excludes)) {
Expand Down Expand Up @@ -85,7 +79,6 @@ export class AgentBackup {
*/
async restore(jwe: string, options?: BackupOptions) {
const masterSk = await this.masterSk(options);
// const masterSk = await this.masterSk();
const jwk = masterSk.to.JWK();
const JWE = await this.getJWE();
const decoded = JWE.decrypt(
Expand Down Expand Up @@ -153,8 +146,9 @@ export class AgentBackup {
* @returns JWK
*/
private async masterSk(options?: BackupOptions) {
if (notNil(options?.key)) {
return options.key;
const optKey = options?.key;
if (notNil(optKey)) {
return optKey;
}

const masterKey = this.Agent.apollo.createPrivateKey({
Expand Down
22 changes: 9 additions & 13 deletions src/edge-agent/Agent.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as Domain from "../domain";
import Apollo from "../apollo";
import Castor from "../castor";
import Pollux from "../pollux";
import { Startable } from "../domain/protocols/Startable";
import { AgentBackup } from "./Agent.Backup";
import { SignWithDID } from "./didFunctions/Sign";
Expand All @@ -10,6 +9,7 @@ import { FetchApi } from "./helpers/FetchApi";
import { Task } from "../utils/tasks";
import { notNil } from "../utils";
import { RevealCredentialFields } from "./helpers/RevealCredentialFields";
import { RunProtocol } from "./helpers/RunProtocol";

/**
* Edge agent implementation
Expand All @@ -20,7 +20,6 @@ import { RevealCredentialFields } from "./helpers/RevealCredentialFields";
*/
export default class Agent extends Startable.Controller {
public backup: AgentBackup;
public readonly pollux: Domain.Pollux;

/**
* Creates an instance of Agent.
Expand All @@ -41,14 +40,6 @@ export default class Agent extends Startable.Controller {
) {
super();
this.backup = new AgentBackup(this);
// this.pollux = new Pollux(apollo, castor);
this.pollux = new Pollux({
Apollo: this.apollo,
Castor: this.castor,
Pluto: this.pluto,
Seed: this.seed,
Api: this.api,
});
}

/**
Expand Down Expand Up @@ -103,8 +94,14 @@ export default class Agent extends Startable.Controller {
return this.runTask(task);
}

isCredentialRevoked(credential: Domain.Credential) {
return this.pollux.handle("revocation-check", "prism/jwt", credential);
async isCredentialRevoked(credential: Domain.Credential): Promise<boolean> {
const result = await this.runTask(new RunProtocol({
type: "revocation-check",
pid: "prism/jwt",
data: { credential }
}));

return result.data;
}

private runTask<T>(task: Task<T>) {
Expand All @@ -113,7 +110,6 @@ export default class Agent extends Startable.Controller {
Apollo: this.apollo,
Castor: this.castor,
Pluto: this.pluto,
Pollux: this.pollux,
Seed: this.seed,
});

Expand Down
Loading

0 comments on commit ffe2e9c

Please sign in to comment.