From 15c82590f2ef9c1e8ae51e9d6e2eb6e2c9d3bd78 Mon Sep 17 00:00:00 2001 From: lenkan Date: Fri, 1 Dec 2023 15:45:50 +0100 Subject: [PATCH] add npm ci, linting, format check to workflow --- .github/workflows/main.yml | 18 +++- .../integration-scripts/credentials.test.ts | 20 +++-- .../integration-scripts/singlesig-ixn.test.ts | 42 ++++++--- .../integration-scripts/singlesig-rot.test.ts | 42 ++++++--- .../test-setup-clients.test.ts | 24 +++--- .../test-setup-single-client.test.ts | 62 +++++++++----- .../integration-scripts/utils/resolve-env.ts | 6 +- .../integration-scripts/utils/test-setup.ts | 85 ++++++++++++++----- .../integration-scripts/utils/test-util.ts | 10 ++- package.json | 3 +- src/keri/app/controller.ts | 12 ++- src/keri/app/grouping.ts | 3 +- src/keri/app/habery.ts | 3 +- src/keri/core/decrypter.ts | 6 +- src/keri/core/eventing.ts | 5 +- src/keri/core/indexer.ts | 12 ++- src/keri/core/manager.ts | 5 +- src/keri/core/matter.ts | 4 +- src/keri/core/tholder.ts | 5 +- test/app/grouping.test.ts | 9 +- test/core/encrypter.test.ts | 3 +- test/core/manager.test.ts | 6 +- 22 files changed, 269 insertions(+), 116 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ff4ff131..d0f11fe5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,13 +27,23 @@ jobs: node-version: '18.12.1' cache: 'npm' - - name: build + - name: Install dependencies run: | npm cache clean --force npm set registry https://registry.npmjs.org/ - npm i - npm test -- --coverage=true - npm run build + npm ci + + - name: Check formatting + run: npm run pretty:check + + - name: Lint + run: npm run lint + + - name: Test + run: npm test -- --coverage=true + + - name: Build + run: npm run build - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v3 diff --git a/examples/integration-scripts/credentials.test.ts b/examples/integration-scripts/credentials.test.ts index d49db9ae..d9712ce4 100644 --- a/examples/integration-scripts/credentials.test.ts +++ b/examples/integration-scripts/credentials.test.ts @@ -115,10 +115,12 @@ test('credentials', async () => { const verifierAidName = 'verifier'; // Create two identifiers, one for each client - const issuerIcpRes = await issuerClient.identifiers().create(issuerAidName, { - toad: 3, - wits: [...KLI_WITNESS_DEMO_PREFIXES], - }); + const issuerIcpRes = await issuerClient + .identifiers() + .create(issuerAidName, { + toad: 3, + wits: [...KLI_WITNESS_DEMO_PREFIXES], + }); let issOp = await issuerIcpRes.op(); while (!issOp['done']) { issOp = await issuerClient.operations().get(issOp.name); @@ -131,10 +133,12 @@ test('credentials', async () => { .addEndRole(issuerAidName, 'agent', issuerClient!.agent!.pre); console.log("Issuer's AID:", issuerAID); - const holderIcpRes = await holderClient.identifiers().create(holderAidName, { - toad: 3, - wits: [...KLI_WITNESS_DEMO_PREFIXES], - }); + const holderIcpRes = await holderClient + .identifiers() + .create(holderAidName, { + toad: 3, + wits: [...KLI_WITNESS_DEMO_PREFIXES], + }); let hldOp = await holderIcpRes.op(); while (!hldOp['done']) { hldOp = await holderClient.operations().get(hldOp.name); diff --git a/examples/integration-scripts/singlesig-ixn.test.ts b/examples/integration-scripts/singlesig-ixn.test.ts index 20df9484..1986ba6a 100644 --- a/examples/integration-scripts/singlesig-ixn.test.ts +++ b/examples/integration-scripts/singlesig-ixn.test.ts @@ -1,6 +1,10 @@ -import { EventResult, SignifyClient } from "signify-ts"; -import { getOrCreateClients, getOrCreateContact, getOrCreateIdentifier } from "./utils/test-setup"; -import { waitOperation } from "./utils/test-util"; +import { EventResult, SignifyClient } from 'signify-ts'; +import { + getOrCreateClients, + getOrCreateContact, + getOrCreateIdentifier, +} from './utils/test-setup'; +import { waitOperation } from './utils/test-util'; let client1: SignifyClient, client2: SignifyClient; let name1_id: string, name1_oobi: string; @@ -10,20 +14,20 @@ beforeAll(async () => { [client1, client2] = await getOrCreateClients(2); }); beforeAll(async () => { - [name1_id, name1_oobi] = await getOrCreateIdentifier(client1, "name1"); + [name1_id, name1_oobi] = await getOrCreateIdentifier(client1, 'name1'); }); beforeAll(async () => { - contact1_id = await getOrCreateContact(client2, "contact1", name1_oobi); + contact1_id = await getOrCreateContact(client2, 'contact1', name1_oobi); }); interface KeyState { i: string; s: string; - [property: string]: any + [property: string]: any; } -describe("singlesig-ixn", () => { - test("step1", async () => { +describe('singlesig-ixn', () => { + test('step1', async () => { expect(name1_id).toEqual(contact1_id); const keystate1 = await client1.keyStates().get(name1_id); @@ -35,28 +39,38 @@ describe("singlesig-ixn", () => { // local and remote keystate sequence match expect(keystate1[0].s).toEqual(keystate2[0].s); }); - test("ixn1", async () => { + test('ixn1', async () => { // local keystate before ixn - const keystate0: KeyState = (await client1.keyStates().get(name1_id)).at(0); + const keystate0: KeyState = ( + await client1.keyStates().get(name1_id) + ).at(0); expect(keystate0).not.toBeNull(); // ixn - const result: EventResult = await client1.identifiers().interact("name1", {}); + const result: EventResult = await client1 + .identifiers() + .interact('name1', {}); await waitOperation(client1, await result.op()); // local keystate after ixn - const keystate1: KeyState = (await client1.keyStates().get(name1_id)).at(0); + const keystate1: KeyState = ( + await client1.keyStates().get(name1_id) + ).at(0); expect(parseInt(keystate1.s)).toBeGreaterThan(0); // sequence has incremented expect(parseInt(keystate1.s)).toEqual(parseInt(keystate0.s) + 1); // remote keystate after ixn - const keystate2: KeyState = (await client2.keyStates().get(contact1_id)).at(0); + const keystate2: KeyState = ( + await client2.keyStates().get(contact1_id) + ).at(0); // remote keystate is one behind expect(parseInt(keystate2.s)).toEqual(parseInt(keystate1.s) - 1); // refresh remote keystate - let op = await client2.keyStates().query(contact1_id, parseInt(keystate1.s), undefined); + let op = await client2 + .keyStates() + .query(contact1_id, parseInt(keystate1.s), undefined); op = await waitOperation(client2, op); const keystate3: KeyState = op.response; // local and remote keystate match diff --git a/examples/integration-scripts/singlesig-rot.test.ts b/examples/integration-scripts/singlesig-rot.test.ts index 3f88fb92..d5a7af91 100644 --- a/examples/integration-scripts/singlesig-rot.test.ts +++ b/examples/integration-scripts/singlesig-rot.test.ts @@ -1,6 +1,10 @@ -import { EventResult, RotateIdentifierArgs, SignifyClient } from "signify-ts"; -import { getOrCreateClients, getOrCreateContact, getOrCreateIdentifier } from "./utils/test-setup"; -import { waitOperation } from "./utils/test-util"; +import { EventResult, RotateIdentifierArgs, SignifyClient } from 'signify-ts'; +import { + getOrCreateClients, + getOrCreateContact, + getOrCreateIdentifier, +} from './utils/test-setup'; +import { waitOperation } from './utils/test-util'; let client1: SignifyClient, client2: SignifyClient; let name1_id: string, name1_oobi: string; @@ -10,10 +14,10 @@ beforeAll(async () => { [client1, client2] = await getOrCreateClients(2); }); beforeAll(async () => { - [name1_id, name1_oobi] = await getOrCreateIdentifier(client1, "name1"); + [name1_id, name1_oobi] = await getOrCreateIdentifier(client1, 'name1'); }); beforeAll(async () => { - contact1_id = await getOrCreateContact(client2, "contact1", name1_oobi); + contact1_id = await getOrCreateContact(client2, 'contact1', name1_oobi); }); interface KeyState { @@ -21,11 +25,11 @@ interface KeyState { s: string; k: string[]; n: string[]; - [property: string]: any + [property: string]: any; } -describe("singlesig-rot", () => { - test("step1", async () => { +describe('singlesig-rot', () => { + test('step1', async () => { expect(name1_id).toEqual(contact1_id); const keystate1 = await client1.keyStates().get(name1_id); @@ -37,20 +41,26 @@ describe("singlesig-rot", () => { // local and remote keystate sequence match expect(keystate1[0].s).toEqual(keystate2[0].s); }); - test("rot1", async () => { + test('rot1', async () => { // local keystate before rot - const keystate0: KeyState = (await client1.keyStates().get(name1_id)).at(0); + const keystate0: KeyState = ( + await client1.keyStates().get(name1_id) + ).at(0); expect(keystate0).not.toBeNull(); expect(keystate0.k).toHaveLength(1); expect(keystate0.n).toHaveLength(1); // rot const args: RotateIdentifierArgs = {}; - const result: EventResult = await client1.identifiers().rotate("name1", args); + const result: EventResult = await client1 + .identifiers() + .rotate('name1', args); await waitOperation(client1, await result.op()); // local keystate after rot - const keystate1: KeyState = (await client1.keyStates().get(name1_id)).at(0); + const keystate1: KeyState = ( + await client1.keyStates().get(name1_id) + ).at(0); expect(parseInt(keystate1.s)).toBeGreaterThan(0); // sequence has incremented expect(parseInt(keystate1.s)).toEqual(parseInt(keystate0.s) + 1); @@ -60,12 +70,16 @@ describe("singlesig-rot", () => { expect(keystate1.n[0]).not.toEqual(keystate0.n[0]); // remote keystate after rot - const keystate2: KeyState = (await client2.keyStates().get(contact1_id)).at(0); + const keystate2: KeyState = ( + await client2.keyStates().get(contact1_id) + ).at(0); // remote keystate is one behind expect(parseInt(keystate2.s)).toEqual(parseInt(keystate1.s) - 1); // refresh remote keystate - let op = await client2.keyStates().query(contact1_id, parseInt(keystate1.s), undefined); + let op = await client2 + .keyStates() + .query(contact1_id, parseInt(keystate1.s), undefined); op = await waitOperation(client2, op); const keystate3: KeyState = op.response; // local and remote keystate match diff --git a/examples/integration-scripts/test-setup-clients.test.ts b/examples/integration-scripts/test-setup-clients.test.ts index 29540239..906f8528 100644 --- a/examples/integration-scripts/test-setup-clients.test.ts +++ b/examples/integration-scripts/test-setup-clients.test.ts @@ -1,29 +1,33 @@ -import { SignifyClient } from "signify-ts"; -import { getOrCreateClients, getOrCreateContact, getOrCreateIdentifier } from "./utils/test-setup"; +import { SignifyClient } from 'signify-ts'; +import { + getOrCreateClients, + getOrCreateContact, + getOrCreateIdentifier, +} from './utils/test-setup'; let client1: SignifyClient, client2: SignifyClient; let name1_id: string, name1_oobi: string; let name2_id: string, name2_oobi: string; -let contact1_id: string, contact2_id: string;; +let contact1_id: string, contact2_id: string; beforeAll(async () => { // create two clients with random secrets [client1, client2] = await getOrCreateClients(2); }); beforeAll(async () => { - [name1_id, name1_oobi] = await getOrCreateIdentifier(client1, "name1"); - [name2_id, name2_oobi] = await getOrCreateIdentifier(client2, "name2"); + [name1_id, name1_oobi] = await getOrCreateIdentifier(client1, 'name1'); + [name2_id, name2_oobi] = await getOrCreateIdentifier(client2, 'name2'); }); beforeAll(async () => { - contact1_id = await getOrCreateContact(client2, "contact1", name1_oobi); - contact2_id = await getOrCreateContact(client1, "contact2", name2_oobi); + contact1_id = await getOrCreateContact(client2, 'contact1', name1_oobi); + contact2_id = await getOrCreateContact(client1, 'contact2', name2_oobi); }); -describe("test-setup-clients", () => { - test("step1", async () => { +describe('test-setup-clients', () => { + test('step1', async () => { expect(name1_id).toEqual(contact1_id); }); - test("step2", async () => { + test('step2', async () => { expect(name2_id).toEqual(contact2_id); }); }); diff --git a/examples/integration-scripts/test-setup-single-client.test.ts b/examples/integration-scripts/test-setup-single-client.test.ts index f8be928f..32bb084b 100644 --- a/examples/integration-scripts/test-setup-single-client.test.ts +++ b/examples/integration-scripts/test-setup-single-client.test.ts @@ -1,39 +1,59 @@ -import { SignifyClient } from "signify-ts"; -import { getOrCreateClients, getOrCreateIdentifier } from "./utils/test-setup"; -import { resolveEnvironment } from "./utils/resolve-env"; +import { SignifyClient } from 'signify-ts'; +import { getOrCreateClients, getOrCreateIdentifier } from './utils/test-setup'; +import { resolveEnvironment } from './utils/resolve-env'; let client: SignifyClient; let name1_id: string, name1_oobi: string; beforeAll(async () => { // Create client with pre-defined secret. Allows working with known identifiers - [client] = await getOrCreateClients(1, ["0ADF2TpptgqcDE5IQUF1HeTp"]); + [client] = await getOrCreateClients(1, ['0ADF2TpptgqcDE5IQUF1HeTp']); }); beforeAll(async () => { - [name1_id, name1_oobi] = await getOrCreateIdentifier(client, "name1"); + [name1_id, name1_oobi] = await getOrCreateIdentifier(client, 'name1'); }); -describe("test-setup-single-client", () => { - test("step1", async () => { - expect(client.agent?.pre).toEqual("EC60ue9GOpQGrLBlS9T0dO6JkBTbv3V05Y4O730QBBoc"); - expect(client.controller?.pre).toEqual("EB3UGWwIMq7ppzcQ697ImQIuXlBG5jzh-baSx-YG3-tY"); +describe('test-setup-single-client', () => { + test('step1', async () => { + expect(client.agent?.pre).toEqual( + 'EC60ue9GOpQGrLBlS9T0dO6JkBTbv3V05Y4O730QBBoc' + ); + expect(client.controller?.pre).toEqual( + 'EB3UGWwIMq7ppzcQ697ImQIuXlBG5jzh-baSx-YG3-tY' + ); }); - test("step2", async () => { + test('step2', async () => { const env = resolveEnvironment(); - const oobi = await client.oobis().get("name1", "witness"); + const oobi = await client.oobis().get('name1', 'witness'); expect(oobi.oobis).toHaveLength(3); switch (env.preset) { - case "local": - expect(name1_oobi).toEqual(`http://localhost:3902/oobi/${name1_id}/agent/EC60ue9GOpQGrLBlS9T0dO6JkBTbv3V05Y4O730QBBoc`); - expect(oobi.oobis[0]).toEqual(`http://localhost:5642/oobi/${name1_id}/witness/BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha`); - expect(oobi.oobis[1]).toEqual(`http://localhost:5643/oobi/${name1_id}/witness/BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM`); - expect(oobi.oobis[2]).toEqual(`http://localhost:5644/oobi/${name1_id}/witness/BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX`); + case 'local': + expect(name1_oobi).toEqual( + `http://localhost:3902/oobi/${name1_id}/agent/EC60ue9GOpQGrLBlS9T0dO6JkBTbv3V05Y4O730QBBoc` + ); + expect(oobi.oobis[0]).toEqual( + `http://localhost:5642/oobi/${name1_id}/witness/BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha` + ); + expect(oobi.oobis[1]).toEqual( + `http://localhost:5643/oobi/${name1_id}/witness/BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM` + ); + expect(oobi.oobis[2]).toEqual( + `http://localhost:5644/oobi/${name1_id}/witness/BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX` + ); break; - case "docker": - expect(name1_oobi).toEqual(`http://keria:3902/oobi/${name1_id}/agent/EC60ue9GOpQGrLBlS9T0dO6JkBTbv3V05Y4O730QBBoc`); - expect(oobi.oobis[0]).toEqual(`http://witness-demo:5642/oobi/${name1_id}/witness/BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha`); - expect(oobi.oobis[1]).toEqual(`http://witness-demo:5643/oobi/${name1_id}/witness/BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM`); - expect(oobi.oobis[2]).toEqual(`http://witness-demo:5644/oobi/${name1_id}/witness/BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX`); + case 'docker': + expect(name1_oobi).toEqual( + `http://keria:3902/oobi/${name1_id}/agent/EC60ue9GOpQGrLBlS9T0dO6JkBTbv3V05Y4O730QBBoc` + ); + expect(oobi.oobis[0]).toEqual( + `http://witness-demo:5642/oobi/${name1_id}/witness/BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha` + ); + expect(oobi.oobis[1]).toEqual( + `http://witness-demo:5643/oobi/${name1_id}/witness/BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM` + ); + expect(oobi.oobis[2]).toEqual( + `http://witness-demo:5644/oobi/${name1_id}/witness/BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX` + ); break; } }); diff --git a/examples/integration-scripts/utils/resolve-env.ts b/examples/integration-scripts/utils/resolve-env.ts index 9cb1cf79..d41ce4d1 100644 --- a/examples/integration-scripts/utils/resolve-env.ts +++ b/examples/integration-scripts/utils/resolve-env.ts @@ -9,9 +9,9 @@ export interface TestEnvironment { witnessIds: string[]; } -const WAN = "BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha"; -const WIL = "BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM"; -const WES = "BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX"; +const WAN = 'BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha'; +const WIL = 'BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM'; +const WES = 'BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX'; export function resolveEnvironment( input?: TestEnvironmentPreset diff --git a/examples/integration-scripts/utils/test-setup.ts b/examples/integration-scripts/utils/test-setup.ts index 0dc253f6..ea9760f1 100644 --- a/examples/integration-scripts/utils/test-setup.ts +++ b/examples/integration-scripts/utils/test-setup.ts @@ -1,6 +1,13 @@ -import { CreateIdentiferArgs, EventResult, SignifyClient, Tier, randomPasscode, ready } from "signify-ts"; -import { resolveEnvironment } from "./resolve-env"; -import { waitOperation } from "./test-util"; +import { + CreateIdentiferArgs, + EventResult, + SignifyClient, + Tier, + randomPasscode, + ready, +} from 'signify-ts'; +import { resolveEnvironment } from './resolve-env'; +import { waitOperation } from './test-util'; /** * Connect or boot a number of SignifyClient instances @@ -14,25 +21,32 @@ import { waitOperation } from "./test-util"; * Launch jest from shell with pre-defined secrets * $ SIGNIFY_SECRETS="0ACqshJKkJ7DDXcaDuwnmI8s,0ABqicvyicXGvIVg6Ih-dngE" npx jest ./tests */ -export async function getOrCreateClients(count: number, brans: string[] | undefined = undefined): Promise { +export async function getOrCreateClients( + count: number, + brans: string[] | undefined = undefined +): Promise { const tasks: Promise[] = []; - const secrets = process.env["SIGNIFY_SECRETS"]?.split(","); + const secrets = process.env['SIGNIFY_SECRETS']?.split(','); for (let i = 0; i < count; i++) { - tasks.push(getOrCreateClient(brans?.at(i) ?? secrets?.at(i) ?? undefined)); + tasks.push( + getOrCreateClient(brans?.at(i) ?? secrets?.at(i) ?? undefined) + ); } const clients: SignifyClient[] = await Promise.all(tasks); - console.log(`SIGNIFY_SECRETS="${clients.map(i => i.bran).join(",")}"`); + console.log(`SIGNIFY_SECRETS="${clients.map((i) => i.bran).join(',')}"`); return clients; } /** * Connect or boot a SignifyClient instance */ -export async function getOrCreateClient(bran: string | undefined = undefined): Promise { +export async function getOrCreateClient( + bran: string | undefined = undefined +): Promise { const env = resolveEnvironment(); await ready(); bran ??= randomPasscode(); - bran = bran.padEnd(21, "_"); + bran = bran.padEnd(21, '_'); const client = new SignifyClient(env.url, bran, Tier.low, env.bootUrl); try { await client.connect(); @@ -41,7 +55,10 @@ export async function getOrCreateClient(bran: string | undefined = undefined): P if (!res.ok) throw new Error(); await client.connect(); } - console.log("client", { agent: client.agent?.pre, controller: client.controller.pre }); + console.log('client', { + agent: client.agent?.pre, + controller: client.controller.pre, + }); return client; } @@ -55,7 +72,11 @@ export async function getOrCreateClient(bran: string | undefined = undefined): P * }); * @see resolveEnvironment */ -export async function getOrCreateIdentifier(client: SignifyClient, name: string, kargs: CreateIdentiferArgs | undefined = undefined): Promise<[string, string]> { +export async function getOrCreateIdentifier( + client: SignifyClient, + name: string, + kargs: CreateIdentiferArgs | undefined = undefined +): Promise<[string, string]> { let id: any = undefined; try { const identfier = await client.identifiers().get(name); @@ -65,22 +86,26 @@ export async function getOrCreateIdentifier(client: SignifyClient, name: string, const env = resolveEnvironment(); kargs ??= { toad: env.witnessIds.length, - wits: env.witnessIds + wits: env.witnessIds, }; - const result: EventResult = await client.identifiers().create(name, kargs); + const result: EventResult = await client + .identifiers() + .create(name, kargs); let op = await result.op(); op = await waitOperation(client, op); // console.log("identifiers.create", op); id = op.response.i; } const eid = client.agent?.pre!; - if (!await hasEndRole(client, name, "agent", eid)) { - const result: EventResult = await client.identifiers().addEndRole(name, "agent", eid); + if (!(await hasEndRole(client, name, 'agent', eid))) { + const result: EventResult = await client + .identifiers() + .addEndRole(name, 'agent', eid); let op = await result.op(); op = await waitOperation(client, op); // console.log("identifiers.addEndRole", op); } - const oobi = await client.oobis().get(name, "agent"); + const oobi = await client.oobis().get(name, 'agent'); const result: [string, string] = [id, oobi.oobis[0]]; console.log(name, result); return result; @@ -89,9 +114,16 @@ export async function getOrCreateIdentifier(client: SignifyClient, name: string, /** * Get list of end role authorizations for a Keri idenfitier */ -export async function getEndRoles(client: SignifyClient, alias: string, role?: string): Promise { - const path = (role !== undefined) ? `/identifiers/${alias}/endroles/${role}` : `/identifiers/${alias}/endroles`; - const response: Response = await client.fetch(path, "GET", null); +export async function getEndRoles( + client: SignifyClient, + alias: string, + role?: string +): Promise { + const path = + role !== undefined + ? `/identifiers/${alias}/endroles/${role}` + : `/identifiers/${alias}/endroles`; + const response: Response = await client.fetch(path, 'GET', null); if (!response.ok) throw new Error(await response.text()); const result = await response.json(); // console.log("getEndRoles", result); @@ -101,7 +133,12 @@ export async function getEndRoles(client: SignifyClient, alias: string, role?: s /** * Test if end role is authorized for a Keri identifier */ -export async function hasEndRole(client: SignifyClient, alias: string, role: string, eid: string): Promise { +export async function hasEndRole( + client: SignifyClient, + alias: string, + role: string, + eid: string +): Promise { const list = await getEndRoles(client, alias, role); for (const i of list) { if (i.role === role && i.eid === eid) { @@ -120,8 +157,12 @@ export async function hasEndRole(client: SignifyClient, alias: string, role: str * contact1_id = await getOrCreateContact(client2, "contact1", name1_oobi); * }); */ -export async function getOrCreateContact(client: SignifyClient, name: string, oobi: string): Promise { - const list = await client.contacts().list(undefined, "alias", `^${name}$`); +export async function getOrCreateContact( + client: SignifyClient, + name: string, + oobi: string +): Promise { + const list = await client.contacts().list(undefined, 'alias', `^${name}$`); // console.log("contacts.list", list); if (list.length > 0) { const contact = list[0]; diff --git a/examples/integration-scripts/utils/test-util.ts b/examples/integration-scripts/utils/test-util.ts index df0f7505..bfd2d821 100644 --- a/examples/integration-scripts/utils/test-util.ts +++ b/examples/integration-scripts/utils/test-util.ts @@ -1,7 +1,7 @@ -import { SignifyClient } from "signify-ts"; +import { SignifyClient } from 'signify-ts'; export function sleep(ms: number): Promise { - return new Promise(resolve => { + return new Promise((resolve) => { setTimeout(resolve, ms); }); } @@ -9,7 +9,11 @@ export function sleep(ms: number): Promise { /** * Poll for operation to become completed */ -export async function waitOperation(client: SignifyClient, op: any, retries: number | undefined = undefined): Promise { +export async function waitOperation( + client: SignifyClient, + op: any, + retries: number | undefined = undefined +): Promise { const WAIT = 500; // 0.5 seconds retries ??= 10; // default 10 retries or 5 seconds while (retries-- > 0) { diff --git a/package.json b/package.json index a75d79af..3275be3b 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ "lint": "npx eslint src test examples/integration-scripts examples/scripts", "prepare": "npm run build", "generate-docs": "node_modules/.bin/jsdoc --configure .jsdoc.json --verbose", - "pretty": "prettier --config .prettierrc 'src/**/*.ts' 'test/**/*.ts' 'examples/**/*.ts' --write" + "pretty": "prettier --config .prettierrc 'src/**/*.ts' 'test/**/*.ts' 'examples/**/*.ts' --write", + "pretty:check": "prettier --config .prettierrc 'src/**/*.ts' 'test/**/*.ts' 'examples/**/*.ts' --check" }, "name": "signify-ts", "author": "Phil Feairheller", diff --git a/src/keri/app/controller.ts b/src/keri/app/controller.ts index e9fdac06..af4c5c6a 100644 --- a/src/keri/app/controller.ts +++ b/src/keri/app/controller.ts @@ -113,7 +113,11 @@ export class Controller { this.salter = new Salter({ qb64: this.bran, tier: this.tier }); - const creator = new SaltyCreator(this.salter.qb64, this.tier, this.stem); + const creator = new SaltyCreator( + this.salter.qb64, + this.tier, + this.stem + ); this.signer = creator .create( @@ -209,7 +213,11 @@ export class Controller { const nsalter = new Salter({ qb64: nbran, tier: this.tier }); const nsigner = this.salter.signer(undefined, false); - const creator = new SaltyCreator(this.salter.qb64, this.tier, this.stem); + const creator = new SaltyCreator( + this.salter.qb64, + this.tier, + this.stem + ); const signer = creator .create( undefined, diff --git a/src/keri/app/grouping.ts b/src/keri/app/grouping.ts index 0de192c6..f9745499 100644 --- a/src/keri/app/grouping.ts +++ b/src/keri/app/grouping.ts @@ -82,10 +82,9 @@ export class Groups { sigs: sigs, gid: gid, smids: smids, - rmids: rmids + rmids: rmids, }; const res = await this.client.fetch(path, method, data); return await res.json(); } - } diff --git a/src/keri/app/habery.ts b/src/keri/app/habery.ts index 08da4b3e..3339a27b 100644 --- a/src/keri/app/habery.ts +++ b/src/keri/app/habery.ts @@ -76,7 +76,8 @@ export class Habery { } } let algo; - const salter = salt != undefined ? new Salter({ qb64: salt }) : undefined; + const salter = + salt != undefined ? new Salter({ qb64: salt }) : undefined; if (salt != undefined) { algo = Algos.salty; } else { diff --git a/src/keri/core/decrypter.ts b/src/keri/core/decrypter.ts index b1ca0538..9be6a1d4 100644 --- a/src/keri/core/decrypter.ts +++ b/src/keri/core/decrypter.ts @@ -64,7 +64,11 @@ export class Decrypter extends Matter { _x25519(cipher: Cipher, prikey: Uint8Array, transferable: boolean = false) { const pubkey = libsodium.crypto_scalarmult_base(prikey); - const plain = libsodium.crypto_box_seal_open(cipher.raw, pubkey, prikey); + const plain = libsodium.crypto_box_seal_open( + cipher.raw, + pubkey, + prikey + ); if (cipher.code == MtrDex.X25519_Cipher_Salt) { return new Salter({ qb64b: plain }); } else if (cipher.code == MtrDex.X25519_Cipher_Seed) { diff --git a/src/keri/core/eventing.ts b/src/keri/core/eventing.ts index ff4af89b..6daa175f 100644 --- a/src/keri/core/eventing.ts +++ b/src/keri/core/eventing.ts @@ -433,7 +433,10 @@ export function messagize( .qb64b ); atc = concat(atc, new TextEncoder().encode(seal[1].i)); - atc = concat(atc, new Seqner({sn: parseInt(seal[1].s)}).qb64b); + atc = concat( + atc, + new Seqner({ sn: parseInt(seal[1].s) }).qb64b + ); atc = concat(atc, new TextEncoder().encode(seal[1].d)); } else if (seal[0] == 'SealLast') { atc = concat( diff --git a/src/keri/core/indexer.ts b/src/keri/core/indexer.ts index a4f52b9c..8649ca55 100644 --- a/src/keri/core/indexer.ts +++ b/src/keri/core/indexer.ts @@ -43,7 +43,9 @@ export class IndexedSigCodex { Ed448_Big_Crt_Sig: string = '3B'; // Ed448 signature appears in current list only. has(prop: string): boolean { - const m = new Map(Array.from(Object.entries(this), (v) => [v[1], v[0]])); + const m = new Map( + Array.from(Object.entries(this), (v) => [v[1], v[0]]) + ); return m.has(prop); } } @@ -61,7 +63,9 @@ export class IndexedCurrentSigCodex { Ed448_Big_Crt_Sig: string = '3B'; // Ed448 signature appears in current list only. has(prop: string): boolean { - const m = new Map(Array.from(Object.entries(this), (v) => [v[1], v[0]])); + const m = new Map( + Array.from(Object.entries(this), (v) => [v[1], v[0]]) + ); return m.has(prop); } } @@ -77,7 +81,9 @@ export class IndexedBothSigCodex { Ed448_Big_Sig: string = '3A'; // Ed448 signature appears in both lists. has(prop: string): boolean { - const m = new Map(Array.from(Object.entries(this), (v) => [v[1], v[0]])); + const m = new Map( + Array.from(Object.entries(this), (v) => [v[1], v[0]]) + ); return m.has(prop); } } diff --git a/src/keri/core/manager.ts b/src/keri/core/manager.ts index 8742043f..dbbb8f2d 100644 --- a/src/keri/core/manager.ts +++ b/src/keri/core/manager.ts @@ -216,7 +216,10 @@ export function openManager(passcode: string, salt?: string) { } const bran = MtrDex.Salt_128 + 'A' + passcode.substring(0, 21); // qb64 salt for seed - const signer = new Salter({ qb64: bran }).signer(MtrDex.Ed25519_Seed, false); + const signer = new Salter({ qb64: bran }).signer( + MtrDex.Ed25519_Seed, + false + ); const seed = signer.qb64; const aeid = signer.verfer.qb64; // lest it remove encryption diff --git a/src/keri/core/matter.ts b/src/keri/core/matter.ts index 03e51b27..8abaedf7 100644 --- a/src/keri/core/matter.ts +++ b/src/keri/core/matter.ts @@ -7,7 +7,9 @@ import { Buffer } from 'buffer'; export class Codex { has(prop: string): boolean { - const m = new Map(Array.from(Object.entries(this), (v) => [v[1], v[0]])); + const m = new Map( + Array.from(Object.entries(this), (v) => [v[1], v[0]]) + ); return m.has(prop); } } diff --git a/src/keri/core/tholder.ts b/src/keri/core/tholder.ts index b6d18c0d..4221df25 100644 --- a/src/keri/core/tholder.ts +++ b/src/keri/core/tholder.ts @@ -80,7 +80,10 @@ export class Tholder { private _processLimen(limen: string) { const matter = new Matter({ qb64: limen }); if (NumDex.has(matter.code)) { - const number = new CesrNumber({ raw: matter.raw, code: matter.code }); + const number = new CesrNumber({ + raw: matter.raw, + code: matter.code, + }); this._processUnweighted(number.num); } else if (BexDex.has(matter.code)) { // TODO: Implement Bexter diff --git a/test/app/grouping.test.ts b/test/app/grouping.test.ts index 4b408725..9685af03 100644 --- a/test/app/grouping.test.ts +++ b/test/app/grouping.test.ts @@ -182,7 +182,14 @@ describe('Grouping', () => { ); assert.equal(lastCall[1]!.method, 'GET'); - await groups.join('aid1', { 'ked': {} }, ['sig'], 'ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose00', ['1', '2', '3'], ['a', 'b', 'c']); + await groups.join( + 'aid1', + { ked: {} }, + ['sig'], + 'ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose00', + ['1', '2', '3'], + ['a', 'b', 'c'] + ); lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length - 1]!; assert.equal(lastCall[0]!, url + '/identifiers/aid1/multisig/join'); assert.equal(lastCall[1]!.method, 'POST'); diff --git a/test/core/encrypter.test.ts b/test/core/encrypter.test.ts index 53c27d79..5aff91cc 100644 --- a/test/core/encrypter.test.ts +++ b/test/core/encrypter.test.ts @@ -32,7 +32,8 @@ describe('Encrypter', () => { 114, ]); const saltqb64 = new Matter({ raw: salt, code: MtrDex.Salt_128 }).qb64; - const saltqb64b = new Matter({ raw: salt, code: MtrDex.Salt_128 }).qb64b; + const saltqb64b = new Matter({ raw: salt, code: MtrDex.Salt_128 }) + .qb64b; assert.equal(saltqb64, '0AA2CGQNobs5jXCNoMATSody'); // b'h,#|\x8ap"\x12\xc43t2\xa6\xe1\x18\x19\xf0f2,y\xc4\xc21@\xf5@\x15.\xa2\x1a\xcf' diff --git a/test/core/manager.test.ts b/test/core/manager.test.ts index ce4881b6..2fc78a3e 100644 --- a/test/core/manager.test.ts +++ b/test/core/manager.test.ts @@ -212,7 +212,11 @@ describe('Manager', () => { const encrypter1 = new Encrypter({}, b(aeid1)); assert.equal(encrypter1.verifySeed(seed1), true); - const manager = new Manager({ seed: seed0, salter: salter, aeid: aeid0 }); + const manager = new Manager({ + seed: seed0, + salter: salter, + aeid: aeid0, + }); assert.equal(manager.encrypter!.qb64, encrypter0.qb64); assert.equal(manager.decrypter!.qb64, decrypter0.qb64); assert.equal(manager.seed, seed0);