Skip to content

Commit da4f5c3

Browse files
committed
docs: add key management and siginput docs
1 parent 5996d11 commit da4f5c3

File tree

5 files changed

+112
-25
lines changed

5 files changed

+112
-25
lines changed

src/keri/app/controller.ts

Lines changed: 79 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

src/keri/app/credentialing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ export class Credentials {
332332
}
333333

334334
/**
335-
* Issue a credential
335+
* Creates a credential in the specified registry to be GRANTed with IPEX to the intended recipient
336336
*/
337337
async issue(
338338
name: string,

src/keri/core/httping.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,16 @@ export interface SiginputArgs {
3333
context?: string;
3434
}
3535

36+
/**
37+
* Generates, serializes, and signs a Signature-Input HTTP header value as a structured header
38+
* @param signer
39+
* @param sigInputArgs
40+
*/
3641
export function siginput(
3742
signer: Signer,
38-
{
43+
sigInputArgs: SiginputArgs
44+
): [Map<string, string>, Siger | Cigar] {
45+
const {
3946
name,
4047
method,
4148
path,
@@ -46,8 +53,7 @@ export function siginput(
4653
alg,
4754
keyid,
4855
context,
49-
}: SiginputArgs
50-
): [Map<string, string>, Siger | Cigar] {
56+
} = sigInputArgs;
5157
const items = new Array<string>();
5258
const ifields = new Array<[string, Map<string, string>]>();
5359

src/keri/core/manager.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,23 @@ export class RandyCreator implements Creator {
205205
return new Keys(signers);
206206
}
207207

208+
/**
209+
* Unused for random key generation.
210+
*/
208211
get salt(): string {
209212
return '';
210213
}
211214

215+
/**
216+
* Unused for random key generation.
217+
*/
212218
get stem(): string {
213219
return '';
214220
}
215221

222+
/**
223+
* Unused for random key generation.
224+
*/
216225
get tier(): Tier {
217226
return '' as Tier;
218227
}

src/keri/core/salter.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,19 @@ export class Salter extends Matter {
127127
}
128128

129129
/**
130-
* Returns Signer with .raw secret derived from code size, path, .raw salt, and tier.
131-
* The signer's public key for its .verfer is derived from code and transferable.
130+
* Returns Signer with the private key secret derived from code the path, the user entered passcode as a salt,
131+
* and the security tier sized by the CESR cryptographic seed size indicated by the code. See the example below.
132+
* The Signer's public key for its .verfer is derived from its private key, the Matter code, and the transferable boolean.
133+
*
134+
* The construction of the raw hash bytes used looks like this:
135+
* ( size, password, salt )
136+
* where
137+
* ( code size, path, Base64Decode(passcode) )
138+
* for example, for the initial inception signing key the following parameters are used:
139+
* ( 32, "signify:controller00", Base64Decode("Athisismysecretkeyseed") )
140+
* and for the initial rotation key pair the following parameters are used:
141+
* ( 32, "signify:controller01", Base64Decode("Athisismysecretkeyseed") )
142+
*
132143
* @param code derivation code indicating seed type
133144
* @param transferable whether or not the key is for a transferable or non-transferable identifier.
134145
* @param path string of bytes prepended (prefixed) to the salt before stretching
@@ -145,7 +156,7 @@ export class Salter extends Matter {
145156
const seed = this.stretch(Matter._rawSize(code), path, tier, temp);
146157

147158
return new Signer({
148-
raw: seed,
159+
raw: seed, // private key
149160
code: code,
150161
transferable: transferable,
151162
});

0 commit comments

Comments
 (0)