signify-ts 0.2.1 → 0.3.0-rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +48 -26
  2. package/dist/exports.d.ts +1 -1
  3. package/dist/index.d.ts +0 -1
  4. package/dist/keri/app/aiding.d.ts +29 -9
  5. package/dist/keri/app/clienting.d.ts +28 -13
  6. package/dist/keri/app/contacting.d.ts +31 -19
  7. package/dist/keri/app/coring.d.ts +26 -2
  8. package/dist/keri/app/credentialing.d.ts +183 -49
  9. package/dist/keri/app/delegating.d.ts +18 -0
  10. package/dist/keri/app/exchanging.d.ts +4 -3
  11. package/dist/keri/app/notifying.d.ts +1 -1
  12. package/dist/keri/core/base64.d.ts +4 -0
  13. package/dist/keri/core/core.d.ts +2 -0
  14. package/dist/keri/core/httping.d.ts +2 -0
  15. package/dist/keri/core/keeping.d.ts +60 -41
  16. package/dist/keri/core/saider.d.ts +1 -0
  17. package/dist/keri/core/state.d.ts +62 -0
  18. package/dist/keri/end/ending.d.ts +10 -8
  19. package/dist/signify-ts.cjs +672 -534
  20. package/dist/signify-ts.cjs.map +4 -4
  21. package/dist/signify-ts.mjs +673 -535
  22. package/dist/signify-ts.mjs.map +4 -4
  23. package/package.json +33 -10
  24. package/src/exports.ts +1 -1
  25. package/src/index.ts +0 -1
  26. package/src/keri/app/aiding.ts +64 -35
  27. package/src/keri/app/clienting.ts +47 -50
  28. package/src/keri/app/contacting.ts +36 -21
  29. package/src/keri/app/coring.ts +81 -3
  30. package/src/keri/app/credentialing.ts +361 -197
  31. package/src/keri/app/delegating.ts +33 -0
  32. package/src/keri/app/exchanging.ts +24 -21
  33. package/src/keri/app/notifying.ts +2 -2
  34. package/src/keri/core/authing.ts +12 -5
  35. package/src/keri/core/base64.ts +28 -0
  36. package/src/keri/core/bexter.ts +4 -3
  37. package/src/keri/core/core.ts +2 -0
  38. package/src/keri/core/diger.ts +1 -1
  39. package/src/keri/core/eventing.ts +4 -4
  40. package/src/keri/core/httping.ts +6 -3
  41. package/src/keri/core/indexer.ts +4 -4
  42. package/src/keri/core/keeping.ts +143 -105
  43. package/src/keri/core/matter.ts +5 -5
  44. package/src/keri/core/number.ts +1 -1
  45. package/src/keri/core/prefixer.ts +2 -2
  46. package/src/keri/core/saider.ts +1 -1
  47. package/src/keri/core/serder.ts +1 -1
  48. package/src/keri/core/state.ts +69 -0
  49. package/src/keri/core/tholder.ts +5 -6
  50. package/src/keri/end/ending.ts +78 -81
  51. package/dist/buffer-polyfill.d.ts +0 -1
  52. package/dist/index.js +0 -8
  53. package/dist/math.d.ts +0 -1
  54. package/dist/signify-ts.cjs.development.js +0 -9501
  55. package/dist/signify-ts.cjs.development.js.map +0 -1
  56. package/dist/signify-ts.cjs.production.min.js +0 -2
  57. package/dist/signify-ts.cjs.production.min.js.map +0 -1
  58. package/dist/signify-ts.esm.js +0 -9345
  59. package/dist/signify-ts.esm.js.map +0 -1
  60. package/src/buffer-polyfill.ts +0 -5
  61. package/src/math.ts +0 -3
package/README.md CHANGED
@@ -9,7 +9,7 @@ Project Name: signify-ts
9
9
 
10
10
  ## Signify - KERI Signing at the Edge
11
11
 
12
- Of the five functions in a KERI agent,
12
+ Of the five functions in a KERI agent,
13
13
 
14
14
  1. Key generation
15
15
  2. Encrypted key storage
@@ -19,20 +19,18 @@ Of the five functions in a KERI agent,
19
19
 
20
20
  Signify-TS splits off two, key generation and event signing into a TypeScript library to provide "signing at the edge".
21
21
  It accomplishes this by using [libsodium](https://doc.libsodium.org/) to generate ed25519 key pairs for signing and x25519 key pairs for encrypting the
22
- private keys, next public keys and salts used to generate the private keys. The encrypted private key and salts are then stored on a
23
- remote cloud agent that never has access to the decryption keys. New key pair sets (current and next) will be generated
22
+ private keys, next public keys and salts used to generate the private keys. The encrypted private key and salts are then stored on a
23
+ remote cloud agent that never has access to the decryption keys. New key pair sets (current and next) will be generated
24
24
  for inception and rotation events with only the public keys and blake3 hash of the next keys made available to the agent.
25
25
 
26
26
  The communication protocol between a Signify client and [KERI](https://github.com/WebOfTrust/keri) agent will encode all cryptographic primitives as CESR base64
27
- encoded strings for the initial implementation. Support for binary CESR can be added in the future.
28
-
27
+ encoded strings for the initial implementation. Support for binary CESR can be added in the future.
29
28
 
30
29
  ### Environment Setup
31
30
 
32
31
  The code is built using Typescript and running code locally requires a Mac or Linux OS.
33
32
 
34
- - Install [Node.js](https://nodejs.org)
35
-
33
+ - Install [Node.js](https://nodejs.org)
36
34
 
37
35
  - Install dependencies:
38
36
  ```bash
@@ -42,10 +40,31 @@ The code is built using Typescript and running code locally requires a Mac or Li
42
40
  Typescript source files needs to be transpiled before running scripts or integration tests
43
41
 
44
42
  - Build:
43
+
45
44
  ```bash
46
45
  npm run build
47
46
  ```
48
47
 
48
+ - ready() must be called before library is useable. Example minimum viable client code.
49
+
50
+ ```javascript
51
+ import { randomPasscode, ready, SignifyClient, Tier } from 'signify-ts';
52
+
53
+ await ready();
54
+
55
+ const bran = randomPasscode();
56
+ const url = 'http://127.0.0.1:3901';
57
+ const boot_url = 'http://127.0.0.1:3903';
58
+ const actualSignifyClient = new SignifyClient(
59
+ url,
60
+ bran,
61
+ Tier.low,
62
+ boot_url
63
+ );
64
+
65
+ console.log(actualSignifyClient);
66
+ ```
67
+
49
68
  ### Unit testing
50
69
 
51
70
  To run unit tests
@@ -59,22 +78,34 @@ npm test
59
78
  The integration tests depends on a local instance of KERIA, vLEI-Server and Witness Demo. These are specified in the [Docker Compose](./docker-compose.yaml) file. To start the dependencies, use docker compose:
60
79
 
61
80
  ```bash
62
- docker compose up deps
81
+ docker compose up --wait
63
82
  ```
64
83
 
65
84
  If successful, it should print someting like this:
66
85
 
67
86
  ```bash
68
- $ docker compose up deps
69
- [+] Running 5/4
87
+ $ docker compose up --wait
88
+ [+] Running 4/4
70
89
  ✔ Network signify-ts_default Created 0.0s
71
- ✔ Container signify-ts-vlei-server-1 Created 0.1s
72
- ✔ Container signify-ts-keria-1 Created 0.1s
73
- ✔ Container signify-ts-witness-demo-1 Created 0.1s
74
- ✔ Container signify-ts-deps-1 Created 0.0s
75
- Attaching to signify-ts-deps-1
76
- signify-ts-deps-1 | Dependencies running
77
- signify-ts-deps-1 exited with code 0
90
+ ✔ Container signify-ts-vlei-server-1 Healthy 5.7s
91
+ ✔ Container signify-ts-keria-1 Healthy 6.2s
92
+ ✔ Container signify-ts-witness-demo-1 Healthy 6.2s
93
+ ```
94
+
95
+ It is possible to change the keria image by using environment variables. For example, to use weboftrust/keria:0.1.3, do:
96
+
97
+ ```bash
98
+ export KERIA_IMAGE_TAG=0.1.3
99
+ docker compose pull
100
+ docker compose up --wait
101
+ ```
102
+
103
+ To use another repository, you can do:
104
+
105
+ ```bash
106
+ export KERIA_IMAGE=gleif/keria
107
+ docker compose pull
108
+ docker compose up --wait
78
109
  ```
79
110
 
80
111
  **Important!** The integration tests runs on the build output in `dist/` directory. Make sure to run build before running the integration tests.
@@ -103,19 +134,10 @@ TEST_ENVIRONMENT=local npx jest examples/integration-scripts/credentials.test.ts
103
134
 
104
135
  This changes the discovery urls to use `localhost` instead of the hostnames inside the docker network.
105
136
 
106
- ### Old integration scripts
107
-
108
- To run any of the old integration scripts that has not yet been converted to an integration test. Use `ts-node-esm`
109
-
110
- ```bash
111
- npx ts-node-esm examples/integration-scripts/challenge.ts
112
- ```
113
-
114
137
  # Diagrams
115
138
 
116
139
  Account Creation Workflow
117
140
 
118
141
  ![Account Creation](/diagrams/account-creation-workflow.png)
119
142
 
120
-
121
143
  ![Account Creation Webpage](/diagrams/account-creation-webpage-workflow.png)
package/dist/exports.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from './ready';
2
- export * from './math';
3
2
  export * from './keri/app/habery';
4
3
  export * from './keri/app/controller';
5
4
  export * from './keri/app/aiding';
@@ -37,4 +36,5 @@ export * from './keri/core/signer';
37
36
  export * from './keri/core/tholder';
38
37
  export * from './keri/core/utils';
39
38
  export * from './keri/core/verfer';
39
+ export * from './keri/core/state';
40
40
  export * from './keri/end/ending';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import './buffer-polyfill';
2
1
  import * as exp from './exports';
3
2
  export * from './exports';
4
3
  export default exp;
@@ -2,6 +2,7 @@ import { Tier } from '../core/salter';
2
2
  import { Algos } from '../core/manager';
3
3
  import { Serder } from '../core/serder';
4
4
  import { KeyManager } from '../core/keeping';
5
+ import { HabState } from '../core/state';
5
6
  /** Arguments required to create an identfier */
6
7
  export interface CreateIdentiferArgs {
7
8
  transferable?: boolean;
@@ -19,9 +20,9 @@ export interface CreateIdentiferArgs {
19
20
  rstates?: any[];
20
21
  prxs?: any[];
21
22
  nxts?: any[];
22
- mhab?: any;
23
- keys?: any[];
24
- ndigs?: any[];
23
+ mhab?: HabState;
24
+ keys?: string[];
25
+ ndigs?: string[];
25
26
  bran?: string;
26
27
  count?: number;
27
28
  ncount?: number;
@@ -51,6 +52,12 @@ export interface IdentifierDeps {
51
52
  pidx: number;
52
53
  manager: KeyManager | null;
53
54
  }
55
+ /**
56
+ * Updatable information for a managed identifier
57
+ */
58
+ export interface IdentifierInfo {
59
+ name: string;
60
+ }
54
61
  /** Identifier */
55
62
  export declare class Identifier {
56
63
  client: IdentifierDeps;
@@ -70,10 +77,18 @@ export declare class Identifier {
70
77
  /**
71
78
  * Get information for a managed identifier
72
79
  * @async
73
- * @param {string} name Name or alias of the identifier
74
- * @returns {Promise<any>} A promise to the identifier information
80
+ * @param {string} name Prefix or alias of the identifier
81
+ * @returns {Promise<HabState>} A promise to the identifier information
75
82
  */
76
- get(name: string): Promise<any>;
83
+ get(name: string): Promise<HabState>;
84
+ /**
85
+ * Update managed identifier
86
+ * @async
87
+ * @param {string} name Prefix or alias of the identifier
88
+ * @param {IdentifierInfo} info Information to update for the given identifier
89
+ * @returns {Promise<HabState>} A promise to the identifier information after updating
90
+ */
91
+ update(name: string, info: IdentifierInfo): Promise<HabState>;
77
92
  /**
78
93
  * Create a managed identifier
79
94
  * @async
@@ -85,11 +100,16 @@ export declare class Identifier {
85
100
  /**
86
101
  * Generate an interaction event in a managed identifier
87
102
  * @async
88
- * @param {string} name Name or alias of the identifier
103
+ * @param {string} name Prefix or alias of the identifier
89
104
  * @param {any} [data] Option data to be anchored in the interaction event
90
105
  * @returns {Promise<EventResult>} A promise to the interaction event result
91
106
  */
92
107
  interact(name: string, data?: any): Promise<EventResult>;
108
+ createInteract(name: string, data?: any): Promise<{
109
+ serder: any;
110
+ sigs: any;
111
+ jsondata: any;
112
+ }>;
93
113
  /**
94
114
  * Generate a rotation event in a managed identifier
95
115
  * @param {string} name Name or alias of the identifier
@@ -130,8 +150,8 @@ export declare class Identifier {
130
150
  export declare class EventResult {
131
151
  private readonly _serder;
132
152
  private readonly _sigs;
133
- private readonly promise;
134
- constructor(serder: Serder, sigs: string[], promise: Promise<Response> | Response);
153
+ private readonly response;
154
+ constructor(serder: Serder, sigs: string[], response: Response);
135
155
  get serder(): Serder;
136
156
  get sigs(): string[];
137
157
  op(): Promise<any>;
@@ -1,15 +1,16 @@
1
- import { Agent, Controller } from './controller';
2
- import { Tier } from '../core/salter';
3
1
  import { Authenticater } from '../core/authing';
4
2
  import { ExternalModule, KeyManager } from '../core/keeping';
3
+ import { Tier } from '../core/salter';
5
4
  import { Identifier } from './aiding';
6
5
  import { Contacts, Challenges } from './contacting';
7
- import { Oobis, Operations, KeyEvents, KeyStates } from './coring';
6
+ import { Agent, Controller } from './controller';
7
+ import { Oobis, Operations, KeyEvents, KeyStates, Config } from './coring';
8
8
  import { Credentials, Ipex, Registries, Schemas } from './credentialing';
9
- import { Notifications } from './notifying';
9
+ import { Delegations } from './delegating';
10
10
  import { Escrows } from './escrowing';
11
- import { Groups } from './grouping';
12
11
  import { Exchanges } from './exchanging';
12
+ import { Groups } from './grouping';
13
+ import { Notifications } from './notifying';
13
14
  declare class State {
14
15
  agent: any | null;
15
16
  controller: any | null;
@@ -66,16 +67,20 @@ export declare class SignifyClient {
66
67
  */
67
68
  fetch(path: string, method: string, data: any, extraHeaders?: Headers): Promise<Response>;
68
69
  /**
69
- * Fetch a resource from from an external URL with headers signed by an AID
70
+ * Create a Signed Request to fetch a resource from an external URL with headers signed by an AID
70
71
  * @async
71
- * @param {string} url URL of the resource
72
- * @param {string} path Path to the resource
73
- * @param {string} method HTTP method
74
- * @param {any} data Data to be sent in the body of the resource
75
72
  * @param {string} aidName Name or alias of the AID to be used for signing
76
- * @returns {Promise<Response>} A promise to the result of the fetch
77
- */
78
- signedFetch(url: string, path: string, method: string, data: any, aidName: string): Promise<Response>;
73
+ * @param {string} url URL of the requested resource
74
+ * @param {RequestInit} req Request options should include:
75
+ * - method: HTTP method
76
+ * - data Data to be sent in the body of the resource.
77
+ * If the data is a CESR JSON string then you should also set contentType to 'application/json+cesr'
78
+ * If the data is a FormData object then you should not set the contentType and the browser will set it to 'multipart/form-data'
79
+ * If the data is an object then you should use JSON.stringify to convert it to a string and set the contentType to 'application/json'
80
+ * - contentType Content type of the request.
81
+ * @returns {Promise<Request>} A promise to the created Request
82
+ */
83
+ createSignedRequest(aidName: string, url: string, req: RequestInit): Promise<Request>;
79
84
  /**
80
85
  * Approve the delegation of the client AID to the KERIA agent
81
86
  * @async
@@ -178,5 +183,15 @@ export declare class SignifyClient {
178
183
  * @returns {Exchanges}
179
184
  */
180
185
  exchanges(): Exchanges;
186
+ /**
187
+ * Get delegations resource
188
+ * @returns {Delegations}
189
+ */
190
+ delegations(): Delegations;
191
+ /**
192
+ * Get agent config resource
193
+ * @returns {Config}
194
+ */
195
+ config(): Config;
181
196
  }
182
197
  export {};
@@ -1,5 +1,14 @@
1
1
  import { SignifyClient } from './clienting';
2
2
  import { Operation } from './coring';
3
+ export interface Contact {
4
+ alias: string;
5
+ oobi: string;
6
+ id: string;
7
+ [key: string]: unknown;
8
+ }
9
+ export interface ContactInfo {
10
+ [key: string]: unknown;
11
+ }
3
12
  /**
4
13
  * Contacts
5
14
  */
@@ -18,29 +27,29 @@ export declare class Contacts {
18
27
  * @param {string} [filterValue] Optional field value to filter contacts
19
28
  * @returns {Promise<any>} A promise to the list of contacts
20
29
  */
21
- list(group?: string, filterField?: string, filterValue?: string): Promise<any>;
30
+ list(group?: string, filterField?: string, filterValue?: string): Promise<Contact[]>;
22
31
  /**
23
32
  * Get a contact
24
33
  * @async
25
34
  * @param {string} pre Prefix of the contact
26
35
  * @returns {Promise<any>} A promise to the contact
27
36
  */
28
- get(pre: string): Promise<any>;
37
+ get(pre: string): Promise<Contact>;
29
38
  /**
30
39
  * Add a contact
31
40
  * @async
32
- * @param {string} pre Prefix of the contact
33
- * @param {any} info Information about the contact
34
- * @returns {Promise<any>} A promise to the result of the addition
41
+ * @param pre Prefix of the contact
42
+ * @param info Information about the contact
43
+ * @returns A promise to the result of the addition
35
44
  */
36
- add(pre: string, info: any): Promise<any>;
45
+ add(pre: string, info: ContactInfo): Promise<Contact>;
37
46
  /**
38
47
  * Delete a contact
39
48
  * @async
40
49
  * @param {string} pre Prefix of the contact
41
- * @returns {Promise<any>} A promise to the result of the deletion
50
+ * @returns {Promise<void>}
42
51
  */
43
- delete(pre: string): Promise<any>;
52
+ delete(pre: string): Promise<void>;
44
53
  /**
45
54
  * Update a contact
46
55
  * @async
@@ -48,7 +57,10 @@ export declare class Contacts {
48
57
  * @param {any} info Updated information about the contact
49
58
  * @returns {Promise<any>} A promise to the result of the update
50
59
  */
51
- update(pre: string, info: any): Promise<any>;
60
+ update(pre: string, info: ContactInfo): Promise<Contact>;
61
+ }
62
+ export interface Challenge {
63
+ words: string[];
52
64
  }
53
65
  /**
54
66
  * Challenges
@@ -66,27 +78,27 @@ export declare class Challenges {
66
78
  * @param {number} strength Integer representing the strength of the challenge. Typically 128 or 256
67
79
  * @returns {Promise<any>} A promise to the list of random words
68
80
  */
69
- generate(strength?: number): Promise<any>;
81
+ generate(strength?: number): Promise<Challenge>;
70
82
  /**
71
83
  * Respond to a challenge by signing a message with the list of words
72
84
  * @async
73
- * @param {string} name Name or alias of the identifier
74
- * @param {string} recipient Prefix of the recipient of the response
75
- * @param {Array<string>} words List of words to embed in the signed response
76
- * @returns {Promise<Response>} A promise to the result of the response
85
+ * @param name Name or alias of the identifier
86
+ * @param recipient Prefix of the recipient of the response
87
+ * @param words List of words to embed in the signed response
88
+ * @returns A promise to the result of the response
77
89
  */
78
- respond(name: string, recipient: string, words: string[]): Promise<Response>;
90
+ respond(name: string, recipient: string, words: string[]): Promise<unknown>;
79
91
  /**
80
92
  * Ask Agent to verify a given sender signed the provided words
81
- * @param {string} source Prefix of the identifier that was challenged
82
- * @param {Array<string>} words List of challenge words to check for
93
+ * @param source Prefix of the identifier that was challenged
94
+ * @param words List of challenge words to check for
83
95
  * @returns A promise to the long running operation
84
96
  */
85
97
  verify(source: string, words: string[]): Promise<Operation<unknown>>;
86
98
  /**
87
99
  * Mark challenge response as signed and accepted
88
- * @param {string} source Prefix of the identifier that was challenged
89
- * @param {string} said qb64 AID of exn message representing the signed response
100
+ * @param source Prefix of the identifier that was challenged
101
+ * @param said qb64 AID of exn message representing the signed response
90
102
  * @returns {Promise<Response>} A promise to the result
91
103
  */
92
104
  responded(source: string, said: string): Promise<Response>;
@@ -34,18 +34,24 @@ export interface Operation<T = unknown> {
34
34
  error?: any;
35
35
  response?: T;
36
36
  }
37
+ export interface OperationsDeps {
38
+ fetch(pathname: string, method: string, body: unknown, headers?: Headers): Promise<Response>;
39
+ }
40
+ export interface AgentConfig {
41
+ iurls?: string[];
42
+ }
37
43
  /**
38
44
  * Operations
39
45
  * @remarks
40
46
  * Operations represent the status and result of long running tasks performed by KERIA agent
41
47
  */
42
48
  export declare class Operations {
43
- client: SignifyClient;
49
+ client: OperationsDeps;
44
50
  /**
45
51
  * Operations
46
52
  * @param {SignifyClient} client
47
53
  */
48
- constructor(client: SignifyClient);
54
+ constructor(client: OperationsDeps);
49
55
  /**
50
56
  * Get operation status
51
57
  * @async
@@ -66,6 +72,15 @@ export declare class Operations {
66
72
  * @param {string} name Name of the operation
67
73
  */
68
74
  delete(name: string): Promise<void>;
75
+ /**
76
+ * Poll for operation to become completed.
77
+ */
78
+ wait<T>(op: Operation<T>, options?: {
79
+ signal?: AbortSignal;
80
+ minSleep?: number;
81
+ maxSleep?: number;
82
+ increaseFactor?: number;
83
+ }): Promise<Operation<T>>;
69
84
  }
70
85
  /**
71
86
  * KeyEvents
@@ -119,3 +134,12 @@ export declare class KeyStates {
119
134
  */
120
135
  query(pre: string, sn?: string, anchor?: any): Promise<any>;
121
136
  }
137
+ export declare class Config {
138
+ client: SignifyClient;
139
+ /**
140
+ * Config
141
+ * @param {SignifyClient} client
142
+ */
143
+ constructor(client: SignifyClient);
144
+ get(): Promise<AgentConfig>;
145
+ }