Skip to content

Commit dbffa56

Browse files
authored
refactor: align object names with KERIpy and add function docs (#307)
* refactor: align object names with KERIpy and add function docs * docs: add key management and siginput docs * fix: npm audit failure fix; some tsconfig excludes * docs: Add PubPath docs * docs: correct Salter constructer args docs * refactor: change key state interface names and add docs
1 parent 1e451d1 commit dbffa56

33 files changed

+849
-370
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ The integration tests depends on a local instance of KERIA, vLEI-Server and Witn
8181
docker compose up --wait
8282
```
8383
84-
If successful, it should print someting like this:
84+
If successful, it should print something like this:
8585
8686
```bash
8787
$ docker compose up --wait

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ services:
2121
- 7723:7723
2222

2323
keria:
24-
image: ${KERIA_IMAGE:-weboftrust/keria}:${KERIA_IMAGE_TAG:-0.2.0-dev6}
24+
image: ${KERIA_IMAGE:-weboftrust/keria}:${KERIA_IMAGE_TAG:-0.2.0-rc1}
2525
environment:
2626
KERI_AGENT_CORS: 1
2727
<<: *python-env

examples/integration-scripts/modules/bip39_shim.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { mnemonicToSeedSync, generateMnemonic } from 'bip39';
2-
import { Diger, Signer, MtrDex, Keeper, KeeperResult, Algos } from 'signify-ts';
2+
import {
3+
Diger,
4+
Signer,
5+
MtrDex,
6+
IdentifierManager,
7+
IdentifierManagerResult,
8+
Algos,
9+
} from 'signify-ts';
310

4-
export class BIP39Shim implements Keeper {
11+
export class BIP39Shim implements IdentifierManager {
512
private icount: number;
613
private ncount: number;
714
private dcode: string | undefined;
@@ -49,7 +56,7 @@ export class BIP39Shim implements Keeper {
4956
return keys;
5057
}
5158

52-
async incept(transferable: boolean): Promise<KeeperResult> {
59+
async incept(transferable: boolean): Promise<IdentifierManagerResult> {
5360
const signers = this.keys(this.icount, this.kidx, transferable);
5461
const verfers = signers.map((signer) => signer.verfer.qb64);
5562

@@ -70,7 +77,7 @@ export class BIP39Shim implements Keeper {
7077
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7178
count: any, //number,
7279
transferable: boolean
73-
): Promise<KeeperResult> {
80+
): Promise<IdentifierManagerResult> {
7481
const signers = this.keys(
7582
this.ncount,
7683
this.kidx + this.icount,

examples/integration-scripts/multisig-join.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ describe('multisig-join', () => {
164164
waitOperation(client3, opOobi5),
165165
]);
166166

167+
// rotate single sig
167168
const [rotateResult1, rotateResult2] = await Promise.all([
168169
client1.identifiers().rotate(nameMember1),
169170
client2.identifiers().rotate(nameMember2),
@@ -309,7 +310,7 @@ describe('multisig-join', () => {
309310
.exchanges()
310311
.send(
311312
nameMember1,
312-
nameMultisig,
313+
'multisig',
313314
aid1,
314315
'/multisig/rot',
315316
{ gid: serder1.pre, smids, rmids },

examples/integration-scripts/utils/multisig-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import signify, {
99
messagize,
1010
} from 'signify-ts';
1111
import { getStates, waitAndMarkNotification } from './test-util';
12-
import { HabState } from '../../../src/keri/core/state';
12+
import { HabState } from '../../../src/keri/core/keyState';
1313
import assert from 'assert';
1414

1515
export interface AcceptMultisigInceptArgs {

examples/integration-scripts/utils/test-util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import signify, {
99
Tier,
1010
} from 'signify-ts';
1111
import { RetryOptions, retry } from './retry';
12-
import { HabState } from '../../../src/keri/core/state';
12+
import { HabState } from '../../../src/keri/core/keyState';
1313
import assert from 'assert';
1414
import { resolveEnvironment } from './resolve-env';
1515

package-lock.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/exports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ export * from './keri/core/signer';
3939
export * from './keri/core/tholder';
4040
export * from './keri/core/utils';
4141
export * from './keri/core/verfer';
42-
export * from './keri/core/state';
42+
export * from './keri/core/keyState';
4343

4444
export * from './keri/end/ending';

src/keri/app/aiding.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Tier } from '../core/salter';
22
import { Algos } from '../core/manager';
33
import { incept, interact, reply, rotate } from '../core/eventing';
4-
import { b, Ilks, Serials, Versionage } from '../core/core';
4+
import { b, Ilks, Serials, Vrsn_1_0 } from '../core/core';
55
import { Tholder } from '../core/tholder';
66
import { MtrDex } from '../core/matter';
77
import { Serder } from '../core/serder';
88
import { parseRangeHeaders } from '../core/httping';
9-
import { KeyManager } from '../core/keeping';
10-
import { HabState } from '../core/state';
9+
import { IdentifierManagerFactory } from '../core/keeping';
10+
import { HabState } from '../core/keyState';
1111

1212
/** Arguments required to create an identfier */
1313
export interface CreateIdentiferArgs {
@@ -63,7 +63,7 @@ export interface IdentifierDeps {
6363
headers?: Headers
6464
): Promise<Response>;
6565
pidx: number;
66-
manager: KeyManager | null;
66+
manager: IdentifierManagerFactory | null;
6767
}
6868

6969
/**
@@ -225,7 +225,7 @@ export class Identifier {
225225
wits: wits,
226226
cnfg: [],
227227
data: data,
228-
version: Versionage,
228+
version: Vrsn_1_0,
229229
kind: Serials.JSON,
230230
code: dcode,
231231
intive: false,
@@ -240,7 +240,7 @@ export class Identifier {
240240
wits: wits,
241241
cnfg: [],
242242
data: data,
243-
version: Versionage,
243+
version: Vrsn_1_0,
244244
kind: Serials.JSON,
245245
code: dcode,
246246
intive: false,

src/keri/app/clienting.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Authenticater } from '../core/authing';
22
import { HEADER_SIG_TIME } from '../core/httping';
3-
import { ExternalModule, KeyManager } from '../core/keeping';
3+
import { ExternalModule, IdentifierManagerFactory } from '../core/keeping';
44
import { Tier } from '../core/salter';
55

66
import { Identifier } from './aiding';
@@ -30,15 +30,18 @@ class State {
3030
}
3131
}
3232

33-
/** SignifyClient */
33+
/**
34+
* An in-memory key manager that can connect to a KERIA Agent and use it to
35+
* receive messages and act as a proxy for multi-signature operations and delegation operations.
36+
*/
3437
export class SignifyClient {
3538
public controller: Controller;
3639
public url: string;
3740
public bran: string;
3841
public pidx: number;
3942
public agent: Agent | null;
4043
public authn: Authenticater | null;
41-
public manager: KeyManager | null;
44+
public manager: IdentifierManagerFactory | null;
4245
public tier: Tier;
4346
public bootUrl: string;
4447
public exteralModules: ExternalModule[];
@@ -147,7 +150,7 @@ export class SignifyClient {
147150
if (this.controller.serder.ked.s == 0) {
148151
await this.approveDelegation();
149152
}
150-
this.manager = new KeyManager(
153+
this.manager = new IdentifierManagerFactory(
151154
this.controller.salter,
152155
this.exteralModules
153156
);

src/keri/app/controller.ts

Lines changed: 81 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Diger } from '../core/diger';
55
import { incept, rotate, interact } from '../core/eventing';
66
import { Serder } from '../core/serder';
77
import { Tholder } from '../core/tholder';
8-
import { Ilks, b, Serials, Versionage } from '../core/core';
8+
import { Ilks, b, Serials, Vrsn_1_0 } from '../core/core';
99
import { Verfer } from '../core/verfer';
1010
import { Encrypter } from '../core/encrypter';
1111
import { Decrypter } from '../core/decrypter';
@@ -89,17 +89,67 @@ export class Agent {
8989
* signing key represents the Account for the client on the agent
9090
*/
9191
export class Controller {
92+
/*
93+
The bran is the combination of the first 21 characters of the passcode passed in prefixed with 'A' and '0A'.
94+
Looks like: '0A' + 'A' + 'thisismysecretkeyseed'
95+
Or: "0AAthisismysecretkeyseed"
96+
97+
This is interpreted as encoded Base64URLSafe characters when used as the salt for key generation.
98+
*/
9299
private bran: string;
100+
/**
101+
* The stem is the prefix for the stretched input bytes the controller's cryptographic
102+
* key pairs are derived from.
103+
*/
93104
public stem: string;
105+
/**
106+
* The security tier for the identifiers created by this Controller.
107+
*/
94108
public tier: Tier;
109+
/**
110+
* The rotation index used during key generation by this Controller.
111+
*/
95112
public ridx: number;
113+
/**
114+
* The salter is a cryptographic salt used to derive the controller's cryptographic key pairs
115+
* and is deterministically derived from the bran and the security tier.
116+
*/
96117
public salter: any;
118+
/**
119+
* The current signing key used to sign requests for this controller.
120+
*/
97121
public signer: any;
122+
/**
123+
* The next signing key of which a digest is committed to in an establishment event (inception or rotation) to become the
124+
* signing key after the next rotation.
125+
* @private
126+
*/
98127
private nsigner: any;
128+
/**
129+
* Either the current establishment event, inception or rotation, or the interaction event used for delegation approval.
130+
*/
99131
public serder: Serder;
132+
/**
133+
* Current public keys formatted in fully-qualified Base64.
134+
* @private
135+
*/
100136
private keys: string[];
137+
/**
138+
* Digests of the next public keys formatted in fully-qualified Base64.
139+
*/
101140
public ndigs: string[];
102141

142+
/**
143+
* Creates a Signify Controller starting at key index 0 that generates keys in
144+
* memory based on the provided seed, or bran, the tier, and the rotation index.
145+
*
146+
* The rotation index is used as follows:
147+
*
148+
* @param bran
149+
* @param tier
150+
* @param ridx
151+
* @param state
152+
*/
103153
constructor(
104154
bran: string,
105155
tier: Tier,
@@ -110,6 +160,13 @@ export class Controller {
110160
this.stem = 'signify:controller';
111161
this.tier = tier;
112162
this.ridx = ridx;
163+
const codes = undefined; // Defines the types of seeds that the SaltyCreator will create. Defaults to undefined.
164+
const keyCount = 1; // The number of keys to create. Defaults to 1.
165+
const transferable = true; // Whether the keys are transferable. Defaults to true.
166+
const code = MtrDex.Ed25519_Seed; // The type cryptographic seed to create by default when not overiddeen by "codes".
167+
const pidx = 0; // The index of this identifier prefix of all managed identifiers created for this SignifyClient Controller. Defaults to 0.
168+
const kidx = 0; // The overall starting key index for the first key this rotation set of keys. This is not a local index to this set of keys but an index in the overall set of keys for all keys in this sequence.
169+
// Defaults to 0. Multiply rotation index (ridx) times key count to get the overall key index.
113170

114171
this.salter = new Salter({ qb64: this.bran, tier: this.tier });
115172

@@ -119,30 +176,34 @@ export class Controller {
119176
this.stem
120177
);
121178

179+
// Creates the first key pair used to sign the inception event.
180+
// noinspection UnnecessaryLocalVariableJS
181+
const initialKeyIndex = ridx; // will be zero for inception
122182
this.signer = creator
123183
.create(
124-
undefined,
125-
1,
126-
MtrDex.Ed25519_Seed,
127-
true,
128-
0,
129-
this.ridx,
130-
0,
131-
false
184+
codes,
185+
keyCount,
186+
code,
187+
transferable,
188+
pidx,
189+
initialKeyIndex,
190+
kidx
132191
)
133-
.signers.pop();
192+
.signers.pop(); // assumes only one key pair is created because keyCount is 1
193+
194+
// Creates the second key pair which a digest of the public key is committed to in the inception event.
195+
const nextKeyIndex = ridx + 1;
134196
this.nsigner = creator
135197
.create(
136-
undefined,
137-
1,
138-
MtrDex.Ed25519_Seed,
139-
true,
140-
0,
141-
this.ridx + 1,
142-
0,
143-
false
198+
codes,
199+
keyCount,
200+
code,
201+
transferable,
202+
pidx,
203+
nextKeyIndex,
204+
kidx
144205
)
145-
.signers.pop();
206+
.signers.pop(); // assumes only one key pair is created because keyCount is 1
146207
this.keys = [this.signer.verfer.qb64];
147208
this.ndigs = [
148209
new Diger({ code: MtrDex.Blake3_256 }, this.nsigner.verfer.qb64b)
@@ -173,7 +234,7 @@ export class Controller {
173234
dig: this.serder.ked['d'],
174235
sn: sn,
175236
data: [anchor],
176-
version: Versionage,
237+
version: Vrsn_1_0,
177238
kind: Serials.JSON,
178239
});
179240
return [this.signer.sign(this.serder.raw, 0).qb64];

0 commit comments

Comments
 (0)