bsv-bap 0.1.24 → 0.2.0-alpha.0

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.
@@ -0,0 +1,15 @@
1
+ import { PrivateKey } from "@bsv/sdk";
2
+ import { BaseClass } from "./BaseClass";
3
+ export declare class AccountID extends BaseClass {
4
+ private key;
5
+ constructor(key: PrivateKey);
6
+ getBapId(): string;
7
+ getRootAddress(): string;
8
+ getRootPublicKey(): string;
9
+ signMessage(message: number[]): {
10
+ address: string;
11
+ signature: string;
12
+ };
13
+ getInitialIdTransaction(firstSigningAddress: string): number[][];
14
+ getRevocationTransaction(): number[][];
15
+ }
@@ -1,130 +1,15 @@
1
- import { PublicKey } from "@bsv/sdk";
2
1
  import type { PrivateKey } from "@bsv/sdk";
3
- import type { IdentityAttribute, IdentityAttributes } from "./interface";
4
2
  declare abstract class BaseClass {
5
- protected identityAttributes: IdentityAttributes;
6
- /**
7
- * Abstract method that must be implemented by derived classes to sign messages
8
- * @param message - The message to sign
9
- * @param signingPath - Optional signing path for HD wallets
10
- * @returns Object containing address and signature
11
- */
12
- abstract signMessage(message: number[], signingPath?: string): {
3
+ abstract signMessage(message: number[]): {
13
4
  address: string;
14
5
  signature: string;
15
6
  };
16
- /**
17
- * Abstract method that must be implemented by derived classes to get encryption key
18
- */
19
- abstract getEncryptionKey(): {
20
- privKey: PrivateKey;
21
- pubKey: PublicKey;
22
- };
23
- /**
24
- * Low-level BSM signing helper - signs a message with the given private key
25
- * This consolidates the BSM signing logic used across all signing methods
26
- * @param message - The message to sign as number array
27
- * @param signingKey - The private key to sign with
28
- * @returns Object containing address and base64 signature
29
- */
30
7
  protected signWithBSM(message: number[], signingKey: PrivateKey): {
31
8
  address: string;
32
9
  signature: string;
33
10
  };
34
- /**
35
- * Encrypt the given string data with the identity encryption key
36
- * @param stringData
37
- * @param counterPartyPublicKey Optional public key of the counterparty
38
- * @return string Base64
39
- */
40
- encrypt(stringData: string, counterPartyPublicKey?: string): string;
41
- /**
42
- * Decrypt the given ciphertext with the identity encryption key
43
- * @param ciphertext
44
- * @param counterPartyPublicKey Optional public key of the counterparty
45
- */
46
- decrypt(ciphertext: string, counterPartyPublicKey?: string): string;
47
- /**
48
- * Sign an op_return hex array with AIP
49
- * Each implementation must handle its own signing path logic
50
- * @param opReturn {array}
51
- * @param signingPath {string}
52
- * @return {number[]}
53
- */
54
- signOpReturnWithAIP(opReturn: number[][], signingPath?: string): number[][];
55
- /**
56
- * Returns all the attributes in the identity
57
- * @returns {IdentityAttributes}
58
- */
59
- getAttributes(): IdentityAttributes;
60
- /**
61
- * Get the value of the given attribute
62
- * @param attributeName
63
- * @returns {IdentityAttribute | null}
64
- */
65
- getAttribute(attributeName: string): IdentityAttribute | null;
66
- /**
67
- * Set the value of the given attribute
68
- * If an empty value ('' || null || false) is given, the attribute is removed from the ID
69
- * @param attributeName string
70
- * @param attributeValue any
71
- */
72
- setAttribute(attributeName: string, attributeValue: string | Record<string, string>): void;
73
- /**
74
- * Unset the given attribute from the ID
75
- * @param attributeName
76
- */
77
- unsetAttribute(attributeName: string): void;
78
- /**
79
- * Add an attribute to this identity
80
- * @param attributeName
81
- * @param value
82
- * @param nonce
83
- */
84
- addAttribute(attributeName: string, value: string, nonce?: string): void;
85
- /**
86
- * Get all attribute URNs for this ID
87
- * @returns {string}
88
- */
89
- getAttributeUrns(): string;
90
- /**
91
- * Create and return the attribute URN for the given attribute
92
- * @param attributeName
93
- * @returns {string|null}
94
- */
95
- getAttributeUrn(attributeName: string): string | null;
96
- /**
97
- * Parse a text of URN string into identity attributes
98
- * @param urnIdentityAttributes
99
- */
100
- protected parseStringUrns(urnIdentityAttributes: string): IdentityAttributes;
101
- /**
102
- * Helper function to parse identity attributes
103
- * @param identityAttributes
104
- * @returns {IdentityAttributes}
105
- */
106
- protected parseAttributes(identityAttributes: IdentityAttributes | string): IdentityAttributes;
107
- /**
108
- * Helper method to update an existing attribute
109
- */
110
- protected updateExistingAttribute(attributeName: string, attributeValue: string | Record<string, string>): void;
111
- /**
112
- * Helper method to create a new attribute
113
- */
114
- protected createNewAttribute(attributeName: string, attributeValue: string | Record<string, string>): void;
115
- /**
116
- * Construct an AIP buffer from the op return data
117
- * @param opReturn
118
- * @returns {number[]} Array of numbers representing the buffer
119
- */
11
+ signOpReturnWithAIP(opReturn: number[][]): number[][];
120
12
  protected getAIPMessageBuffer(opReturn: number[][], indicies?: number[]): number[][];
121
- /**
122
- * Helper method to format AIP output
123
- * @param opReturn Original OP_RETURN data
124
- * @param address Signing address
125
- * @param signature Base64 signature
126
- * @returns Formatted AIP output as number[]
127
- */
128
13
  protected formatAIPOutput(opReturnBuffers: number[][], address: string, signature: string): number[][];
129
14
  }
130
15
  export { BaseClass };
@@ -1,297 +1,27 @@
1
- import { PublicKey, type PrivateKey, HD } from "@bsv/sdk";
2
- import { type APIFetcher } from "./api";
3
- import type { GetAttestationResponse, GetSigningKeysResponse } from "./apiTypes";
4
- import type { Identity, IdentityAttributes, OldIdentity, MemberIdentity } from "./interface";
5
- import { MemberID } from "./MemberID";
6
- import { BaseClass } from "./BaseClass";
1
+ import { type PrivateKey, HD } from "@bsv/sdk";
2
+ import type { Identity, OldIdentity } from "./interface";
7
3
  interface Type42KeySource {
8
4
  rootPk: PrivateKey;
9
5
  }
10
- /**
11
- * MasterID class
12
- *
13
- * This class should be used in conjunction with the BAP class
14
- * Supports both BIP32 (HD) and Type 42 key derivation
15
- *
16
- * @type {MasterID}
17
- */
18
- declare class MasterID extends BaseClass {
6
+ declare class MasterID {
19
7
  #private;
20
- idName: string;
21
- description: string;
22
8
  rootAddress: string;
23
- identityKey: string;
24
- identityAttributes: IdentityAttributes;
25
- getApiData: APIFetcher;
26
- constructor(keySource: HD | Type42KeySource, identityAttributes?: IdentityAttributes, idSeed?: string);
27
- set BAP_SERVER(bapServer: string);
28
- get BAP_SERVER(): string;
29
- set BAP_TOKEN(token: string);
30
- get BAP_TOKEN(): string;
31
- deriveIdentityKey(address: string): string;
9
+ bapId: string;
10
+ constructor(keySource: HD | Type42KeySource, idSeed?: string);
32
11
  /**
33
- * Helper function to parse identity attributes
34
- *
35
- * @param identityAttributes
36
- * @returns {{}}
37
- */
38
- parseAttributes(identityAttributes: IdentityAttributes | string): IdentityAttributes;
39
- /**
40
- * Parse a text of urn string into identity attributes
41
- *
42
- * urn:bap:id:name:John Doe:e2c6fb4063cc04af58935737eaffc938011dff546d47b7fbb18ed346f8c4d4fa
43
- * urn:bap:id:birthday:1990-05-22:e61f23cbbb2284842d77965e2b0e32f0ca890b1894ca4ce652831347ee3596d9
44
- * urn:bap:id:over18:1:480ca17ccaacd671b28dc811332525f2f2cd594d8e8e7825de515ce5d52d30e8
45
- *
46
- * @param urnIdentityAttributes
47
- */
48
- parseStringUrns(urnIdentityAttributes: string): IdentityAttributes;
49
- /**
50
- * Returns the identity key
51
- *
52
- * @returns {*|string}
53
- */
54
- getIdentityKey(): string;
55
- /**
56
- * This should be called with the last part of the signing path (/.../.../...)
57
- * This library assumes the first part is m/424150'/0'/0' as defined at the top of this file
58
- *
59
- * @param path The second path of the signing path in the format [0-9]{0,9}/[0-9]{0,9}/[0-9]{0,9}
12
+ * Get the account key (root key) for this identity.
13
+ * This is the cold key used for BAP ID creation and revocation.
60
14
  */
15
+ getAccountKey(): PrivateKey;
16
+ private getPathDerivedKey;
61
17
  set rootPath(path: string);
62
18
  get rootPath(): string;
63
- getRootPath(): string;
64
- /**
65
- * This should be called with the last part of the signing path (/.../.../...)
66
- * This library assumes the first part is m/424150'/0'/0' as defined at the top of this file
67
- *
68
- * @param path The second path of the signing path in the format [0-9]{0,9}/[0-9]{0,9}/[0-9]{0,9}
69
- */
70
19
  set currentPath(path: string);
71
20
  get currentPath(): string;
72
21
  get previousPath(): string;
73
- /**
74
- * This can be used to break the deterministic way child keys are created to make it harder for
75
- * an attacker to steal the identites when the root key is compromised. This does however require
76
- * the seeds to be stored at all times. If the seed is lost, the identity will not be recoverable.
77
- */
78
22
  get idSeed(): string;
79
- /**
80
- * Increment current path to a new path
81
- *
82
- * @returns {*}
83
- */
84
- incrementPath(): void;
85
- /**
86
- * Check whether the given path is a valid path for use with this class
87
- * The signing paths used here always have a length of 3
88
- *
89
- * @param path The last part of the signing path (example "/0/0/1")
90
- * @returns {boolean}
91
- */
92
23
  validatePath(path: string): boolean;
93
- /**
94
- * Get the OP_RETURN for the initial ID transaction (signed with root address)
95
- *
96
- * @returns {[]}
97
- */
98
- getInitialIdTransaction(): number[][];
99
- /**
100
- * Get the OP_RETURN for the ID transaction of the current address / path
101
- *
102
- * @returns {[]}
103
- */
104
- getIdTransaction(previousPath?: string): number[][];
105
- /**
106
- * Get the path-derived private key before identity signing derivation.
107
- *
108
- * At rootPath this is the stable member key that defines the BAP ID.
109
- * At currentPath this is the active wallet root used for signing/wallet operations.
110
- */
111
- private getPathDerivedKey;
112
- /**
113
- * Get the identity signing key for a given path
114
- * This is derived from the path key using the BAP protocol pattern
115
- */
116
- private getIdentitySigningKeyForPath;
117
- /**
118
- * Get the stable member key's public key for this identity.
119
- * This always resolves from rootPath and must not follow currentPath rotations.
120
- */
121
- getMemberKey(): string;
122
- /**
123
- * Get the active wallet root private key for the given path.
124
- * Defaults to currentPath, which follows key rotation.
125
- */
126
- getWalletRoot(path?: string): PrivateKey;
127
- /**
128
- * Get the active wallet root public key for the given path.
129
- * Defaults to currentPath, which follows key rotation.
130
- */
131
- getWalletPubkey(path?: string): string;
132
- /**
133
- * Get the legacy (pre-signing-key-derivation) address for a path
134
- * This is the address without the extra "1-sigma-identity" derivation
135
- */
136
- getLegacyAddress(path?: string): string;
137
- /**
138
- * Check if the on-chain signing address uses legacy derivation
139
- * @param registeredAddress The address registered on-chain (optional, defaults to rootAddress)
140
- * @returns true if the registered address matches legacy derivation
141
- */
142
- needsRotation(registeredAddress?: string): boolean;
143
- /**
144
- * Get OP_RETURN for migrating from legacy to new signing address derivation
145
- * Signs with the LEGACY key to prove ownership of the old address
146
- * Caller handles funding and broadcast
147
- * @returns OP_RETURN data as number[][]
148
- */
149
- getLegacyRotationTransaction(): number[][];
150
- /**
151
- * Get address for given path
152
- * Returns the identity signing address (derived from member key)
153
- *
154
- * @param path
155
- * @returns {*}
156
- */
157
- getAddress(path: string): string;
158
- /**
159
- * Get current signing address
160
- *
161
- * @returns {*}
162
- */
163
- getCurrentAddress(): string;
164
- /**
165
- * Get the encryption key pair for this identity
166
- */
167
- getEncryptionKey(): {
168
- privKey: PrivateKey;
169
- pubKey: PublicKey;
170
- };
171
- /**
172
- * Get the encryption key using type 42 (different key / incompatible with above)
173
- * @deprecated Use getEncryptionKey() which now handles both BIP32 and Type 42
174
- */
175
- getEncryptionKeyType42(): {
176
- privKey: PrivateKey;
177
- pubKey: PublicKey;
178
- };
179
- /**
180
- * Get the public key for encrypting data for this identity
181
- */
182
- getEncryptionPublicKey(): string;
183
- /**
184
- * Get the public key for encrypting data for this identity, using a seed for the encryption
185
- */
186
- getEncryptionPublicKeyWithSeed(seed: string): string;
187
- /**
188
- * Encrypt the given string data with the identity encryption key
189
- * @param stringData
190
- * @param counterPartyPublicKey Optional public key of the counterparty
191
- * @return string Base64
192
- */
193
- encrypt(stringData: string, counterPartyPublicKey?: string): string;
194
- /**
195
- * Decrypt the given ciphertext with the identity encryption key
196
- * @param ciphertext
197
- */
198
- decrypt(ciphertext: string, counterPartyPublicKey?: string): string;
199
- /**
200
- * Encrypt the given string data with the identity encryption key
201
- * @param stringData
202
- * @param seed String seed
203
- * @param counterPartyPublicKey Optional public key of the counterparty
204
- * @return string Base64
205
- */
206
- encryptWithSeed(stringData: string, seed: string, counterPartyPublicKey?: string): string;
207
- /**
208
- * Decrypt the given ciphertext with the identity encryption key
209
- * @param ciphertext
210
- * @param seed String seed
211
- // * @param counterPartyPublicKey Public key of the counterparty
212
- */
213
- decryptWithSeed(ciphertext: string, seed: string, counterPartyPublicKey?: string): string;
214
- private getEncryptionPrivateKeyWithSeed;
215
- /**
216
- * Get an attestation string for the given urn for this identity
217
- *
218
- * @param urn
219
- * @returns {string}
220
- */
221
- getAttestation(urn: string): string;
222
- /**
223
- * Generate and return the attestation hash for the given attribute of this identity
224
- *
225
- * @param attribute Attribute name (name, email etc.)
226
- * @returns {string}
227
- */
228
- getAttestationHash(attribute: string): string | null;
229
- /**
230
- * Sign a message with the current signing address of this identity
231
- * Uses the derived identity signing key
232
- *
233
- * @param message
234
- * @param signingPath
235
- * @returns {{address: string, signature: string}}
236
- */
237
- signMessage(message: number[], signingPath?: string): {
238
- address: string;
239
- signature: string;
240
- };
241
- /**
242
- * Sign a message using a key based on the given string seed
243
- *
244
- * This works by creating a private key from the root key of this identity. It will always
245
- * work with the rootPath / rootKey, to be deterministic. It will not change even if the keys
246
- * are rotated for this ID.
247
- *
248
- * This is used in for instance deterministic login systems, that do not support BAP.
249
- * The signing address is derived from the seed-derived key.
250
- *
251
- * @param message
252
- * @param seed {string} String seed that will be used to generate a path
253
- */
254
- signMessageWithSeed(message: string, seed: string): {
255
- address: string;
256
- signature: string;
257
- };
258
- /**
259
- * Sign an op_return hex array with AIP
260
- * @param opReturn {array}
261
- * @param signingPath {string}
262
- * @return {number[]}
263
- */
264
- signOpReturnWithAIP(opReturn: number[][], signingPath?: string): number[][];
265
- /**
266
- * Get all signing keys for this identity
267
- */
268
- getIdSigningKeys(): Promise<GetSigningKeysResponse>;
269
- /**
270
- * Get all attestations for the given attribute
271
- *
272
- * @param attribute
273
- */
274
- getAttributeAttestations(attribute: string): Promise<GetAttestationResponse>;
275
- /**
276
- * Import an identity from a JSON object
277
- *
278
- * @param identity{{}}
279
- */
280
24
  import(identity: Identity | OldIdentity): void;
281
- /**
282
- * Export this identity to a JSON object
283
- * @returns {{}}
284
- */
285
25
  export(): Identity;
286
- exportMemberBackup(): MemberIdentity;
287
- newId(): MemberID;
288
- /**
289
- * Export member data in bitcoin-backup compatible format
290
- * @returns Object with wif and encrypted member data
291
- */
292
- exportMember(): {
293
- wif: string;
294
- encryptedData: string;
295
- };
296
26
  }
297
27
  export { MasterID };
@@ -6,8 +6,3 @@ export declare const BAP_SERVER = "https://api.sigmaidentity.com/v1";
6
6
  export declare const MAX_INT: number;
7
7
  export declare const SIGNING_PATH_PREFIX = "m/424150'/0'/0'";
8
8
  export declare const ENCRYPTION_PATH = "m/424150'/2147483647'/2147483647'";
9
- export declare const BAP_PROTOCOL_ID: [1, string];
10
- export declare const BAP_KEY_ID = "identity";
11
- export declare const BAP_INVOICE_NUMBER = "1-sigma-identity";
12
- export declare const FRIEND_SECURITY_LEVEL = 2;
13
- export declare const FRIEND_PROTOCOL = "friend";