From f2556c8ab8639141216d12fbf4f634cf69820d7d Mon Sep 17 00:00:00 2001 From: Charles Lanahan Date: Wed, 29 Nov 2023 08:22:10 -0500 Subject: [PATCH 1/3] Impl of dater in signify-ts using cesride-wasm. Implementation example of dater in signify-ts. Right now it just uses a package dependency and a mixture of cesr components from the cesride crate with some constants from signify-ts itself. This is just an example to show the integration works. Also doesn't have feature flags and the dependency is hardcoded into the package.json. dater tests are transcribed into jest from keripy test_dater() Also some todos to be figured out later. --- package.json | 1 + src/keri/core/dater.ts | 0 src/keri/core/helping.ts | 4 ++ src/keri/core/matter.ts | 1 + test/core/dater.test.ts | 124 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 130 insertions(+) create mode 100644 src/keri/core/dater.ts create mode 100644 src/keri/core/helping.ts create mode 100644 test/core/dater.test.ts diff --git a/package.json b/package.json index 810703be..f6593ee6 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,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); + }); +}); + From d16329fa1e2fd3db5cf20f00c7b30f078e504830 Mon Sep 17 00:00:00 2001 From: Charles Lanahan Date: Wed, 29 Nov 2023 09:25:30 -0500 Subject: [PATCH 2/3] Updated README with instructions on how to integrate cesride-wasm --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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) From 81b1415e3f0ee8252dd4e0dd27e6d3adcf7090bd Mon Sep 17 00:00:00 2001 From: Charles Lanahan Date: Wed, 29 Nov 2023 10:51:01 -0500 Subject: [PATCH 3/3] Added ctags .tags to .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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