diff --git a/.gitignore b/.gitignore index 53cce066..2a834e5c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,10 +2,11 @@ .DS_Store node_modules dist +.tags # IntelliJ Project Files .idea coverage/* -examples/signify-react-ts/.cache \ No newline at end of file +examples/signify-react-ts/.cache diff --git a/README.md b/README.md index ad34ea32..ae69a418 100644 --- a/README.md +++ b/README.md @@ -51,5 +51,13 @@ Account Creation Workflow ![Account Creation](/diagrams/account-creation-workflow.png) - ![Account Creation Webpage](/diagrams/account-creation-webpage-workflow.png) + +#### Cesride-WASM (experimental) +If using cesride-wasm you must follow the instructions in the cesride repository in the wasm directory for integrating. Note that these instructions may change in the near future so always be sure to check that README as to the instructions for integrating cesride-wasm into signify-ts. + +Typically the instructions go: +1. Build cesride +2. Build cesride-wasm +3. Add the `/pkg` directory (containing the artifacts of wasm-pack) of cesride-wasm as a dependency to this library +4. Signify-ts should now be able to use cesride-wasm interface. (For debugging cesride\_wasm.d.ts contains the typed interface for the whole crate) diff --git a/package-lock.json b/package-lock.json index 3f2fadca..acae6268 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "dependencies": { "blake3": "^2.1.7", "buffer": "^6.0.3", + "cesride-wasm": "file:///home/daidoji/ssi/cesride/wasm/pkg", "ecdsa-secp256r1": "^1.3.3", "libsodium-wrappers-sumo": "^0.7.9", "mathjs": "^11.8.2", @@ -47,6 +48,10 @@ "whatwg-fetch": "^3.6.19" } }, + "../cesride/wasm/pkg": { + "version": "0.1.0", + "license": "Apache-2.0" + }, "examples/integration-scripts": { "dependencies": { "bip39": "^3.1.0", @@ -4941,6 +4946,10 @@ "node": ">= 10" } }, + "node_modules/cesride-wasm": { + "resolved": "../cesride/wasm/pkg", + "link": true + }, "node_modules/chalk": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", diff --git a/package.json b/package.json index a75d79af..42fa43d3 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "dependencies": { "blake3": "^2.1.7", "buffer": "^6.0.3", + "cesride-wasm": "file:///home/daidoji/ssi/cesride/wasm/pkg", "ecdsa-secp256r1": "^1.3.3", "libsodium-wrappers-sumo": "^0.7.9", "mathjs": "^11.8.2", diff --git a/src/keri/core/dater.ts b/src/keri/core/dater.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/keri/core/helping.ts b/src/keri/core/helping.ts new file mode 100644 index 00000000..e469af09 --- /dev/null +++ b/src/keri/core/helping.ts @@ -0,0 +1,4 @@ +export const DTS_BASE_0 = "2021-01-01T00:00:00.000000+00:00"; +export const DTS_BASE_1 = "2021-01-01T00:00:01.000000+00:00"; +export const DTS_BASE_2 = "2021-01-01T00:01:00.000000+00:00"; +export const DTS_BASE_3 = "2021-01-01T01:00:00.000000+00:00"; diff --git a/src/keri/core/matter.ts b/src/keri/core/matter.ts index e7e3afe4..a484f07b 100644 --- a/src/keri/core/matter.ts +++ b/src/keri/core/matter.ts @@ -33,6 +33,7 @@ export class MatterCodex extends Codex { StrB64_L2: string = '6A'; // String Base64 Only Lead Size 2 ECDSA_256k1N: string = '1AAA'; // ECDSA secp256k1 verification key non-transferable, basic derivation. ECDSA_256k1: string = '1AAB'; // ECDSA public verification or encryption key, basic derivation + DateTime: string = '1AAG'; // Base64 custom encoded 32 char ISO-8601 DateTime X25519_Cipher_Salt: string = '1AAH'; // X25519 100 char b64 Cipher of 24 char qb64 Salt ECDSA_256r1N: string = '1AAI'; // ECDSA secp256r1 verification key non-transferable, basic derivation. ECDSA_256r1: string = '1AAJ'; // ECDSA secp256r1 verification or encryption key, basic derivation diff --git a/test/core/dater.test.ts b/test/core/dater.test.ts new file mode 100644 index 00000000..483a0cca --- /dev/null +++ b/test/core/dater.test.ts @@ -0,0 +1,124 @@ +import { strict as assert } from 'assert'; + +import { Dater } from 'cesride-wasm'; + +import { DTS_BASE_0, DTS_BASE_1 } from '../../src/keri/core/helping'; +import { MtrDex } from '../../src/keri/core/matter'; + +describe('Dater Tests', () => { + test('Test Dater date time subclass of Matter', () => { + let dater = new Dater(); // defaults to now + // TODO(CAL): Figure out change to use cesride MatterCodex instead of signify-ts MtrDex + expect(dater.code).toBe(MtrDex.DateTime); + expect(dater.raw).toHaveLength(24); + expect(dater.qb64).toHaveLength(36); + expect(dater.qb2).toHaveLength(27); + expect(dater.dts).toHaveLength(32); + + const dts1: string = '2020-08-22T17:50:09.988921+00:00'; + const dts1b = new Uint8Array(Buffer.from(dts1)); + const dt1raw = new Uint8Array(Buffer.from('\xdbM\xb4\xfbO>\xdbd\xf5\xed\xcetsO]\xf7\xcf=\xdbZt\xd1\xcd4', 'binary')); + const dt1qb64 = '1AAG2020-08-22T17c50c09d988921p00c00'; + const dt1qb64b = new Uint8Array(Buffer.from(dt1qb64)); + const dt1qb2 = new Uint8Array(Buffer.from('\xd4\x00\x06\xdbM\xb4\xfbO>\xdbd\xf5\xed\xcetsO]\xf7\xcf=\xdbZt\xd1\xcd4', 'binary')); + + dater = new Dater(dts1, undefined, undefined, undefined, undefined, undefined); + expect(dater.raw).toEqual(dt1raw); + expect(dater.code).toBe(MtrDex.DateTime); + expect(dater.dts).toBe(dts1); + expect(dater.dtsb).toEqual(dts1b); + expect(dater.qb64).toBe(dt1qb64); + expect(dater.qb64b).toEqual(dt1qb64b); + expect(dater.qb2).toEqual(dt1qb2); + + // TODO(CAL): Adjust dater in cesride to accept bytes for dts instead of + // just string like in keripy Will create issue. + //dater = new Dater(dts1b, undefined, undefined, undefined, undefined, undefined); + //expect(dater.raw).toEqual(dt1raw); + //expect(dater.code).toBe(MtrDex.DateTime); + ////expect(dater.code).toBe(MatterCodex.DateTime); + //expect(dater.dts).toBe(dts1); + //expect(dater.dtsb).toEqual(dts1b); + //expect(dater.qb64).toBe(dt1qb64); + //expect(dater.qb64b).toEqual(dt1qb64b); + //expect(dater.qb2).toEqual(dt1qb2); + + const dts2 = '2020-08-22T17:50:09.988921-01:00'; + const dts2b = new Uint8Array(Buffer.from(dts2)); + const dt2raw = new Uint8Array(Buffer.from('\xdbM\xb4\xfbO>\xdbd\xf5\xed\xcetsO]\xf7\xcf=\xdb_\xb4\xd5\xcd4', 'binary')); + const dt2qb64 = '1AAG2020-08-22T17c50c09d988921-01c00'; + const dt2qb64b = new Uint8Array(Buffer.from(dt2qb64)); + const dt2qb2 = new Uint8Array(Buffer.from('\xd4\x00\x06\xdbM\xb4\xfbO>\xdbd\xf5\xed\xcetsO]\xf7\xcf=\xdb_\xb4\xd5\xcd4', 'binary')); + + dater = new Dater(dts2, undefined, undefined, undefined, undefined, undefined); + expect(dater.code).toBe(MtrDex.DateTime); + expect(dater.dts).toBe(dts2); + expect(dater.dtsb).toEqual(dts2b); + expect(dater.raw).toEqual(dt2raw); + expect(dater.qb64).toBe(dt2qb64); + expect(dater.qb64b).toEqual(dt2qb64b); + expect(dater.qb2).toEqual(dt2qb2); + + // TODO(CAL): Adjust dater in cesride to accept bytes instead of just string like in keripy + // Will create issue. + //dater = new Dater(dts2b, undefined, undefined, undefined, undefined, undefined); + //expect(dater.code).toBe(MtrDex.DateTime); + ////expect(dater.code).toBe(MatterCodex.DateTime); + //expect(dater.dts).toBe(dts2); + //expect(dater.dtsb).toEqual(dts2b); + //expect(dater.raw).toEqual(dt2raw); + //expect(dater.qb64).toBe(dt2qb64); + //expect(dater.qb64b).toEqual(dt2qb64b); + //expect(dater.qb2).toEqual(dt2qb2); + + dater = new Dater(undefined, MtrDex.DateTime, dt1raw, undefined, undefined, undefined); + //dater = new Dater(undefined, MatterCodex.DateTime, dt1raw, undefined, undefined, undefined); + expect(dater.raw).toEqual(dt1raw); + expect(dater.code).toBe(MtrDex.DateTime); + expect(dater.dts).toBe(dts1); + expect(dater.dtsb).toEqual(dts1b); + expect(dater.qb64).toBe(dt1qb64); + expect(dater.qb64b).toEqual(dt1qb64b); + expect(dater.qb2).toEqual(dt1qb2); + + //TODO(CAL): Adjust dater in cesride to accept bytes for dt1qb64 instead of just string + //dater = new Dater(undefined, undefined, undefined, dt1qb64, undefined, undefined); + //expect(dater.raw).toEqual(dt1raw); + //expect(dater.code).toBe(MtrDex.DateTime); + //expect(dater.dts).toBe(dts1); + //expect(dater.dtsb).toEqual(dts1b); + //expect(dater.qb64).toBe(dt1qb64); + //expect(dater.qb64b).toEqual(dt1qb64b); + //expect(dater.qb2).toEqual(dt1qb2); + + // TODO(CAL): Adjust Dater in cesride to accept bytes instead of just string like in keripy + //dater = new Dater(undefined, undefined, undefined, undefined, dt1qb64b, undefined); + //expect(dater.raw).toEqual(dt1raw); + //expect(dater.code).toBe(MtrDex.DateTime); + //expect(dater.dts).toBe(dts1); + //expect(dater.dtsb).toEqual(dts1b); + //expect(dater.qb64).toBe(dt1qb64); + //expect(dater.qb64b).toEqual(dt1qb64b); + //expect(dater.qb2).toEqual(dt1qb2); + + dater = new Dater(undefined, undefined, undefined, undefined, undefined, dt1qb2); + expect(dater.raw).toEqual(dt1raw); + expect(dater.code).toBe(MtrDex.DateTime); + expect(dater.dts).toBe(dts1); + expect(dater.dtsb).toEqual(dts1b); + expect(dater.qb64).toBe(dt1qb64); + expect(dater.qb64b).toEqual(dt1qb64b); + expect(dater.qb2).toEqual(dt1qb2); + + // Testing datetime properties and comparisons + const dater1 = new Dater(dts1, undefined, undefined, undefined, undefined, undefined); + const dater2 = new Dater(dts2, undefined, undefined, undefined, undefined, undefined); + const dater3 = new Dater(DTS_BASE_0, undefined, undefined, undefined, undefined, undefined); + const dater4 = new Dater(DTS_BASE_1, undefined, undefined, undefined, undefined, undefined); + + // TODO(CAL) implement datetime property in wrapper + //expect(dater1.datetime).toBeLessThan(dater2.datetime); + //expect(dater4.datetime).toBeGreaterThan(dater3.datetime); + }); +}); +