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

Cesride-wasm integration example e2e #149

Closed
wants to merge 4 commits into from
Closed
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
.DS_Store
node_modules
dist
.tags


# IntelliJ Project Files
.idea
coverage/*

examples/signify-react-ts/.cache
examples/signify-react-ts/.cache
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Empty file added src/keri/core/dater.ts
Empty file.
4 changes: 4 additions & 0 deletions src/keri/core/helping.ts
Original file line number Diff line number Diff line change
@@ -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";
1 change: 1 addition & 0 deletions src/keri/core/matter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
124 changes: 124 additions & 0 deletions test/core/dater.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});

Loading