@bsv/sdk 1.3.5 → 1.3.6
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.
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/auth/Peer.js +1 -1
- package/dist/cjs/src/auth/Peer.js.map +1 -1
- package/dist/cjs/src/auth/certificates/Certificate.js +25 -6
- package/dist/cjs/src/auth/certificates/Certificate.js.map +1 -1
- package/dist/cjs/src/auth/certificates/MasterCertificate.js +99 -17
- package/dist/cjs/src/auth/certificates/MasterCertificate.js.map +1 -1
- package/dist/cjs/src/auth/certificates/VerifiableCertificate.js +3 -4
- package/dist/cjs/src/auth/certificates/VerifiableCertificate.js.map +1 -1
- package/dist/cjs/src/auth/certificates/__tests/CompletedProtoWallet.js +80 -0
- package/dist/cjs/src/auth/certificates/__tests/CompletedProtoWallet.js.map +1 -0
- package/dist/cjs/src/auth/certificates/index.js +1 -0
- package/dist/cjs/src/auth/certificates/index.js.map +1 -1
- package/dist/cjs/src/auth/utils/index.js +0 -1
- package/dist/cjs/src/auth/utils/index.js.map +1 -1
- package/dist/cjs/src/wallet/CachedKeyDeriver.js.map +1 -1
- package/dist/cjs/src/wallet/KeyDeriver.js +3 -2
- package/dist/cjs/src/wallet/KeyDeriver.js.map +1 -1
- package/dist/cjs/src/wallet/ProtoWallet.js.map +1 -1
- package/dist/cjs/src/wallet/WalletClient.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/auth/Peer.js +1 -1
- package/dist/esm/src/auth/Peer.js.map +1 -1
- package/dist/esm/src/auth/certificates/Certificate.js +25 -6
- package/dist/esm/src/auth/certificates/Certificate.js.map +1 -1
- package/dist/esm/src/auth/certificates/MasterCertificate.js +100 -18
- package/dist/esm/src/auth/certificates/MasterCertificate.js.map +1 -1
- package/dist/esm/src/auth/certificates/VerifiableCertificate.js +3 -4
- package/dist/esm/src/auth/certificates/VerifiableCertificate.js.map +1 -1
- package/dist/esm/src/auth/certificates/__tests/CompletedProtoWallet.js +76 -0
- package/dist/esm/src/auth/certificates/__tests/CompletedProtoWallet.js.map +1 -0
- package/dist/esm/src/auth/certificates/index.js +1 -0
- package/dist/esm/src/auth/certificates/index.js.map +1 -1
- package/dist/esm/src/auth/utils/index.js +0 -1
- package/dist/esm/src/auth/utils/index.js.map +1 -1
- package/dist/esm/src/wallet/CachedKeyDeriver.js.map +1 -1
- package/dist/esm/src/wallet/KeyDeriver.js +3 -2
- package/dist/esm/src/wallet/KeyDeriver.js.map +1 -1
- package/dist/esm/src/wallet/ProtoWallet.js.map +1 -1
- package/dist/esm/src/wallet/WalletClient.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/auth/Peer.d.ts +1 -1
- package/dist/types/src/auth/Peer.d.ts.map +1 -1
- package/dist/types/src/auth/certificates/Certificate.d.ts +16 -3
- package/dist/types/src/auth/certificates/Certificate.d.ts.map +1 -1
- package/dist/types/src/auth/certificates/MasterCertificate.d.ts +46 -13
- package/dist/types/src/auth/certificates/MasterCertificate.d.ts.map +1 -1
- package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts +1 -1
- package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts.map +1 -1
- package/dist/types/src/auth/certificates/__tests/CompletedProtoWallet.d.ts +24 -0
- package/dist/types/src/auth/certificates/__tests/CompletedProtoWallet.d.ts.map +1 -0
- package/dist/types/src/auth/certificates/index.d.ts +1 -0
- package/dist/types/src/auth/certificates/index.d.ts.map +1 -1
- package/dist/types/src/auth/utils/index.d.ts +0 -1
- package/dist/types/src/auth/utils/index.d.ts.map +1 -1
- package/dist/types/src/wallet/CachedKeyDeriver.d.ts.map +1 -1
- package/dist/types/src/wallet/KeyDeriver.d.ts +5 -7
- package/dist/types/src/wallet/KeyDeriver.d.ts.map +1 -1
- package/dist/types/src/wallet/ProtoWallet.d.ts.map +1 -1
- package/dist/types/src/wallet/Wallet.interfaces.d.ts.map +1 -1
- package/dist/types/src/wallet/WalletClient.d.ts +1 -2
- package/dist/types/src/wallet/WalletClient.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/docs/auth.md +111 -87
- package/docs/wallet.md +26 -97
- package/package.json +1 -1
- package/src/auth/Peer.ts +23 -23
- package/src/auth/__tests/Peer.test.ts +19 -27
- package/src/auth/certificates/Certificate.ts +31 -8
- package/src/auth/certificates/MasterCertificate.ts +134 -23
- package/src/auth/certificates/VerifiableCertificate.ts +6 -6
- package/src/auth/certificates/__tests/Certificate.test.ts +45 -7
- package/src/auth/certificates/__tests/CompletedProtoWallet.ts +101 -0
- package/src/auth/certificates/__tests/MasterCertificate.test.ts +273 -0
- package/src/auth/certificates/__tests/VerifiableCertificate.test.ts +117 -0
- package/src/auth/certificates/index.ts +2 -1
- package/src/auth/utils/index.ts +0 -1
- package/src/wallet/CachedKeyDeriver.ts +1 -2
- package/src/wallet/KeyDeriver.ts +18 -20
- package/src/wallet/ProtoWallet.ts +20 -20
- package/src/wallet/Wallet.interfaces.ts +8 -9
- package/src/wallet/WalletClient.ts +1 -2
- package/src/wallet/__tests/KeyDeriver.test.ts +2 -2
- package/dist/cjs/src/auth/utils/certificateHelpers.js +0 -51
- package/dist/cjs/src/auth/utils/certificateHelpers.js.map +0 -1
- package/dist/esm/src/auth/utils/certificateHelpers.js +0 -47
- package/dist/esm/src/auth/utils/certificateHelpers.js.map +0 -1
- package/dist/types/src/auth/utils/certificateHelpers.d.ts +0 -26
- package/dist/types/src/auth/utils/certificateHelpers.d.ts.map +0 -1
- package/src/auth/utils/certificateHelpers.ts +0 -86
package/src/wallet/KeyDeriver.ts
CHANGED
|
@@ -23,7 +23,7 @@ export interface KeyDeriverApi {
|
|
|
23
23
|
* @param {boolean} [forSelf=false] - Optional. false if undefined. Whether deriving for self.
|
|
24
24
|
* @returns {PublicKey} - The derived public key.
|
|
25
25
|
*/
|
|
26
|
-
derivePublicKey(protocolID: WalletProtocol, keyID: string, counterparty: Counterparty, forSelf?: boolean)
|
|
26
|
+
derivePublicKey: (protocolID: WalletProtocol, keyID: string, counterparty: Counterparty, forSelf?: boolean) => PublicKey
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Derives a private key based on protocol ID, key ID, and counterparty.
|
|
@@ -32,7 +32,7 @@ export interface KeyDeriverApi {
|
|
|
32
32
|
* @param {Counterparty} counterparty - The counterparty's public key or a predefined value ('self' or 'anyone').
|
|
33
33
|
* @returns {PrivateKey} - The derived private key.
|
|
34
34
|
*/
|
|
35
|
-
derivePrivateKey(protocolID: WalletProtocol, keyID: string, counterparty: Counterparty)
|
|
35
|
+
derivePrivateKey: (protocolID: WalletProtocol, keyID: string, counterparty: Counterparty) => PrivateKey
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* Derives a symmetric key based on protocol ID, key ID, and counterparty.
|
|
@@ -41,9 +41,8 @@ export interface KeyDeriverApi {
|
|
|
41
41
|
* @param {string} keyID - The key identifier.
|
|
42
42
|
* @param {Counterparty} counterparty - The counterparty's public key or a predefined value ('self' or 'anyone').
|
|
43
43
|
* @returns {SymmetricKey} - The derived symmetric key.
|
|
44
|
-
* @throws {Error} - Throws an error if attempting to derive a symmetric key for 'anyone'.
|
|
45
44
|
*/
|
|
46
|
-
deriveSymmetricKey(protocolID: WalletProtocol, keyID: string, counterparty: Counterparty)
|
|
45
|
+
deriveSymmetricKey: (protocolID: WalletProtocol, keyID: string, counterparty: Counterparty) => SymmetricKey
|
|
47
46
|
|
|
48
47
|
/**
|
|
49
48
|
* Reveals the shared secret between the root key and the counterparty.
|
|
@@ -52,7 +51,7 @@ export interface KeyDeriverApi {
|
|
|
52
51
|
* @returns {number[]} - The shared secret as a number array.
|
|
53
52
|
* @throws {Error} - Throws an error if attempting to reveal a shared secret for 'self'.
|
|
54
53
|
*/
|
|
55
|
-
revealCounterpartySecret(counterparty: Counterparty)
|
|
54
|
+
revealCounterpartySecret: (counterparty: Counterparty) => number[]
|
|
56
55
|
|
|
57
56
|
/**
|
|
58
57
|
* Reveals the specific key association for a given protocol ID, key ID, and counterparty.
|
|
@@ -61,7 +60,7 @@ export interface KeyDeriverApi {
|
|
|
61
60
|
* @param {string} keyID - The key identifier.
|
|
62
61
|
* @returns {number[]} - The specific key association as a number array.
|
|
63
62
|
*/
|
|
64
|
-
revealSpecificSecret(counterparty: Counterparty, protocolID: WalletProtocol, keyID: string)
|
|
63
|
+
revealSpecificSecret: (counterparty: Counterparty, protocolID: WalletProtocol, keyID: string) => number[]
|
|
65
64
|
}
|
|
66
65
|
|
|
67
66
|
/**
|
|
@@ -76,7 +75,7 @@ export class KeyDeriver implements KeyDeriverApi {
|
|
|
76
75
|
* Initializes the KeyDeriver instance with a root private key.
|
|
77
76
|
* @param {PrivateKey | 'anyone'} rootKey - The root private key or the string 'anyone'.
|
|
78
77
|
*/
|
|
79
|
-
constructor(rootKey: PrivateKey | 'anyone') {
|
|
78
|
+
constructor (rootKey: PrivateKey | 'anyone') {
|
|
80
79
|
if (rootKey === 'anyone') {
|
|
81
80
|
this.rootKey = new PrivateKey(1)
|
|
82
81
|
} else {
|
|
@@ -93,7 +92,7 @@ export class KeyDeriver implements KeyDeriverApi {
|
|
|
93
92
|
* @param {boolean} [forSelf=false] - Whether deriving for self.
|
|
94
93
|
* @returns {PublicKey} - The derived public key.
|
|
95
94
|
*/
|
|
96
|
-
derivePublicKey(protocolID: WalletProtocol, keyID: string, counterparty: Counterparty, forSelf: boolean = false): PublicKey {
|
|
95
|
+
derivePublicKey (protocolID: WalletProtocol, keyID: string, counterparty: Counterparty, forSelf: boolean = false): PublicKey {
|
|
97
96
|
counterparty = this.normalizeCounterparty(counterparty)
|
|
98
97
|
if (forSelf) {
|
|
99
98
|
return this.rootKey.deriveChild(counterparty, this.computeInvoiceNumber(protocolID, keyID)).toPublicKey()
|
|
@@ -109,7 +108,7 @@ export class KeyDeriver implements KeyDeriverApi {
|
|
|
109
108
|
* @param {Counterparty} counterparty - The counterparty's public key or a predefined value ('self' or 'anyone').
|
|
110
109
|
* @returns {PrivateKey} - The derived private key.
|
|
111
110
|
*/
|
|
112
|
-
derivePrivateKey(protocolID: WalletProtocol, keyID: string, counterparty: Counterparty): PrivateKey {
|
|
111
|
+
derivePrivateKey (protocolID: WalletProtocol, keyID: string, counterparty: Counterparty): PrivateKey {
|
|
113
112
|
counterparty = this.normalizeCounterparty(counterparty)
|
|
114
113
|
return this.rootKey.deriveChild(counterparty, this.computeInvoiceNumber(protocolID, keyID))
|
|
115
114
|
}
|
|
@@ -121,18 +120,17 @@ export class KeyDeriver implements KeyDeriverApi {
|
|
|
121
120
|
* @param {string} keyID - The key identifier.
|
|
122
121
|
* @param {Counterparty} counterparty - The counterparty's public key or a predefined value ('self' or 'anyone').
|
|
123
122
|
* @returns {SymmetricKey} - The derived symmetric key.
|
|
124
|
-
* @throws {Error} - Throws an error if attempting to derive a symmetric key for 'anyone'.
|
|
125
123
|
*/
|
|
126
|
-
deriveSymmetricKey(protocolID: WalletProtocol, keyID: string, counterparty: Counterparty): SymmetricKey {
|
|
124
|
+
deriveSymmetricKey (protocolID: WalletProtocol, keyID: string, counterparty: Counterparty): SymmetricKey {
|
|
125
|
+
// If counterparty is 'anyone', we use 1*G as the public key.
|
|
126
|
+
// This is a publicly derivable key and should only be used in scenarios where public disclosure is intended.
|
|
127
127
|
if (counterparty === 'anyone') {
|
|
128
|
-
|
|
129
|
-
'Symmetric keys (such as encryption keys or HMAC keys) should not be derivable by everyone, because messages would be decryptable by anyone who knows the identity public key of the user, and HMACs would be similarly forgeable.'
|
|
130
|
-
)
|
|
128
|
+
counterparty = new PrivateKey(1).toPublicKey()
|
|
131
129
|
}
|
|
132
130
|
counterparty = this.normalizeCounterparty(counterparty)
|
|
133
131
|
const derivedPublicKey = this.derivePublicKey(protocolID, keyID, counterparty)
|
|
134
132
|
const derivedPrivateKey = this.derivePrivateKey(protocolID, keyID, counterparty)
|
|
135
|
-
return new SymmetricKey(derivedPrivateKey.deriveSharedSecret(derivedPublicKey).x
|
|
133
|
+
return new SymmetricKey(derivedPrivateKey.deriveSharedSecret(derivedPublicKey).x.toArray())
|
|
136
134
|
}
|
|
137
135
|
|
|
138
136
|
/**
|
|
@@ -142,7 +140,7 @@ export class KeyDeriver implements KeyDeriverApi {
|
|
|
142
140
|
* @returns {number[]} - The shared secret as a number array.
|
|
143
141
|
* @throws {Error} - Throws an error if attempting to reveal a shared secret for 'self'.
|
|
144
142
|
*/
|
|
145
|
-
revealCounterpartySecret(counterparty: Counterparty): number[] {
|
|
143
|
+
revealCounterpartySecret (counterparty: Counterparty): number[] {
|
|
146
144
|
if (counterparty === 'self') {
|
|
147
145
|
throw new Error('Counterparty secrets cannot be revealed for counterparty=self.')
|
|
148
146
|
}
|
|
@@ -167,7 +165,7 @@ export class KeyDeriver implements KeyDeriverApi {
|
|
|
167
165
|
* @param {string} keyID - The key identifier.
|
|
168
166
|
* @returns {number[]} - The specific key association as a number array.
|
|
169
167
|
*/
|
|
170
|
-
revealSpecificSecret(counterparty: Counterparty, protocolID: WalletProtocol, keyID: string): number[] {
|
|
168
|
+
revealSpecificSecret (counterparty: Counterparty, protocolID: WalletProtocol, keyID: string): number[] {
|
|
171
169
|
counterparty = this.normalizeCounterparty(counterparty)
|
|
172
170
|
const sharedSecret = this.rootKey.deriveSharedSecret(counterparty)
|
|
173
171
|
const invoiceNumberBin = Utils.toArray(this.computeInvoiceNumber(protocolID, keyID), 'utf8')
|
|
@@ -180,7 +178,7 @@ export class KeyDeriver implements KeyDeriverApi {
|
|
|
180
178
|
* @returns {PublicKey} - The normalized counterparty public key.
|
|
181
179
|
* @throws {Error} - Throws an error if the counterparty is invalid.
|
|
182
180
|
*/
|
|
183
|
-
private normalizeCounterparty(counterparty: Counterparty): PublicKey {
|
|
181
|
+
private normalizeCounterparty (counterparty: Counterparty): PublicKey {
|
|
184
182
|
if (!counterparty) {
|
|
185
183
|
throw new Error('counterparty must be self, anyone or a public key!')
|
|
186
184
|
} else if (counterparty === 'self') {
|
|
@@ -201,7 +199,7 @@ export class KeyDeriver implements KeyDeriverApi {
|
|
|
201
199
|
* @returns {string} - The computed invoice number.
|
|
202
200
|
* @throws {Error} - Throws an error if protocol ID or key ID are invalid.
|
|
203
201
|
*/
|
|
204
|
-
private computeInvoiceNumber(protocolID: WalletProtocol, keyID: string): string {
|
|
202
|
+
private computeInvoiceNumber (protocolID: WalletProtocol, keyID: string): string {
|
|
205
203
|
const securityLevel = protocolID[0]
|
|
206
204
|
if (!Number.isInteger(securityLevel) || securityLevel < 0 || securityLevel > 2) {
|
|
207
205
|
throw new Error('Protocol security level must be 0, 1, or 2')
|
|
@@ -243,4 +241,4 @@ export class KeyDeriver implements KeyDeriverApi {
|
|
|
243
241
|
}
|
|
244
242
|
}
|
|
245
243
|
|
|
246
|
-
export default KeyDeriver
|
|
244
|
+
export default KeyDeriver
|
|
@@ -31,48 +31,48 @@ const privilegedError = new Error('ProtoWallet is a single-keyring wallet, opera
|
|
|
31
31
|
/**
|
|
32
32
|
* A ProtoWallet is precursor to a full wallet, capable of performing all foundational cryptographic operations.
|
|
33
33
|
* It can derive keys, create signatures, facilitate encryption and HMAC operations, and reveal key linkages.
|
|
34
|
-
*
|
|
34
|
+
*
|
|
35
35
|
* However, ProtoWallet does not create transactions, manage outputs, interact with the blockchain,
|
|
36
36
|
* enable the management of identity certificates, or store any data.
|
|
37
37
|
*/
|
|
38
38
|
export class ProtoWallet implements ProtoWalletApi {
|
|
39
39
|
keyDeriver: KeyDeriverApi
|
|
40
40
|
|
|
41
|
-
constructor(rootKeyOrKeyDeriver: PrivateKey | 'anyone' | KeyDeriverApi) {
|
|
41
|
+
constructor (rootKeyOrKeyDeriver: PrivateKey | 'anyone' | KeyDeriverApi) {
|
|
42
42
|
if (typeof rootKeyOrKeyDeriver['identityKey'] !== 'string') {
|
|
43
43
|
rootKeyOrKeyDeriver = new KeyDeriver(rootKeyOrKeyDeriver as PrivateKey | 'anyone')
|
|
44
44
|
}
|
|
45
45
|
this.keyDeriver = rootKeyOrKeyDeriver as KeyDeriver
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
async isAuthenticated(args: {}, Originator?: OriginatorDomainNameStringUnder250Bytes): Promise<AuthenticatedResult> {
|
|
48
|
+
async isAuthenticated (args: {}, Originator?: OriginatorDomainNameStringUnder250Bytes): Promise<AuthenticatedResult> {
|
|
49
49
|
return { authenticated: true }
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
async waitForAuthentication(args: {}, Originator?: OriginatorDomainNameStringUnder250Bytes): Promise<AuthenticatedResult> {
|
|
52
|
+
async waitForAuthentication (args: {}, Originator?: OriginatorDomainNameStringUnder250Bytes): Promise<AuthenticatedResult> {
|
|
53
53
|
return { authenticated: true }
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
async getNetwork(args: {}, Originator?: OriginatorDomainNameStringUnder250Bytes): Promise<GetNetworkResult> {
|
|
56
|
+
async getNetwork (args: {}, Originator?: OriginatorDomainNameStringUnder250Bytes): Promise<GetNetworkResult> {
|
|
57
57
|
return { network: 'mainnet' }
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
async getVersion(args: {}, Originator?: OriginatorDomainNameStringUnder250Bytes): Promise<GetVersionResult> {
|
|
60
|
+
async getVersion (args: {}, Originator?: OriginatorDomainNameStringUnder250Bytes): Promise<GetVersionResult> {
|
|
61
61
|
return { version: 'proto-1.0.0' }
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
65
|
* Convenience method to obtain the identityKey.
|
|
66
|
-
* @param originator
|
|
66
|
+
* @param originator
|
|
67
67
|
* @returns `await this.getPublicKey({ identityKey: true }, originator)`
|
|
68
68
|
*/
|
|
69
|
-
async getIdentityKey(
|
|
69
|
+
async getIdentityKey (
|
|
70
70
|
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
71
71
|
): Promise<{ publicKey: PubKeyHex }> {
|
|
72
72
|
return await this.getPublicKey({ identityKey: true }, originator)
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
async getPublicKey(
|
|
75
|
+
async getPublicKey (
|
|
76
76
|
args: GetPublicKeyArgs,
|
|
77
77
|
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
78
78
|
): Promise<{ publicKey: PubKeyHex }> {
|
|
@@ -98,7 +98,7 @@ export class ProtoWallet implements ProtoWalletApi {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
async revealCounterpartyKeyLinkage(
|
|
101
|
+
async revealCounterpartyKeyLinkage (
|
|
102
102
|
args: RevealCounterpartyKeyLinkageArgs,
|
|
103
103
|
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
104
104
|
): Promise<RevealCounterpartyKeyLinkageResult> {
|
|
@@ -136,7 +136,7 @@ export class ProtoWallet implements ProtoWalletApi {
|
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
async revealSpecificKeyLinkage(
|
|
139
|
+
async revealSpecificKeyLinkage (
|
|
140
140
|
args: RevealSpecificKeyLinkageArgs,
|
|
141
141
|
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
142
142
|
): Promise<RevealSpecificKeyLinkageResult> {
|
|
@@ -173,7 +173,7 @@ export class ProtoWallet implements ProtoWalletApi {
|
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
async encrypt(
|
|
176
|
+
async encrypt (
|
|
177
177
|
args: WalletEncryptArgs,
|
|
178
178
|
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
179
179
|
): Promise<WalletEncryptResult> {
|
|
@@ -188,7 +188,7 @@ export class ProtoWallet implements ProtoWalletApi {
|
|
|
188
188
|
return { ciphertext: key.encrypt(args.plaintext) as number[] }
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
async decrypt(
|
|
191
|
+
async decrypt (
|
|
192
192
|
args: WalletDecryptArgs,
|
|
193
193
|
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
194
194
|
): Promise<WalletDecryptResult> {
|
|
@@ -203,7 +203,7 @@ export class ProtoWallet implements ProtoWalletApi {
|
|
|
203
203
|
return { plaintext: key.decrypt(args.ciphertext) as number[] }
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
-
async createHmac(
|
|
206
|
+
async createHmac (
|
|
207
207
|
args: CreateHmacArgs,
|
|
208
208
|
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
209
209
|
): Promise<CreateHmacResult> {
|
|
@@ -218,7 +218,7 @@ export class ProtoWallet implements ProtoWalletApi {
|
|
|
218
218
|
return { hmac: Hash.sha256hmac(key.toArray(), args.data) }
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
async verifyHmac(
|
|
221
|
+
async verifyHmac (
|
|
222
222
|
args: VerifyHmacArgs,
|
|
223
223
|
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
224
224
|
): Promise<VerifyHmacResult> {
|
|
@@ -239,7 +239,7 @@ export class ProtoWallet implements ProtoWalletApi {
|
|
|
239
239
|
return { valid }
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
-
async createSignature(
|
|
242
|
+
async createSignature (
|
|
243
243
|
args: CreateSignatureArgs,
|
|
244
244
|
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
245
245
|
): Promise<CreateSignatureResult> {
|
|
@@ -249,7 +249,7 @@ export class ProtoWallet implements ProtoWalletApi {
|
|
|
249
249
|
if (!args.hashToDirectlySign && !args.data) {
|
|
250
250
|
throw new Error('args.data or args.hashToDirectlySign must be valid')
|
|
251
251
|
}
|
|
252
|
-
const hash: number[] = args.hashToDirectlySign || Hash.sha256(args.data
|
|
252
|
+
const hash: number[] = args.hashToDirectlySign || Hash.sha256(args.data)
|
|
253
253
|
const key = this.keyDeriver.derivePrivateKey(
|
|
254
254
|
args.protocolID,
|
|
255
255
|
args.keyID,
|
|
@@ -258,7 +258,7 @@ export class ProtoWallet implements ProtoWalletApi {
|
|
|
258
258
|
return { signature: ECDSA.sign(new BigNumber(hash), key, true).toDER() as number[] }
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
-
async verifySignature(
|
|
261
|
+
async verifySignature (
|
|
262
262
|
args: VerifySignatureArgs,
|
|
263
263
|
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
264
264
|
): Promise<VerifySignatureResult> {
|
|
@@ -268,7 +268,7 @@ export class ProtoWallet implements ProtoWalletApi {
|
|
|
268
268
|
if (!args.hashToDirectlyVerify && !args.data) {
|
|
269
269
|
throw new Error('args.data or args.hashToDirectlyVerify must be valid')
|
|
270
270
|
}
|
|
271
|
-
const hash: number[] = args.hashToDirectlyVerify || Hash.sha256(args.data
|
|
271
|
+
const hash: number[] = args.hashToDirectlyVerify || Hash.sha256(args.data)
|
|
272
272
|
const key = this.keyDeriver.derivePublicKey(
|
|
273
273
|
args.protocolID,
|
|
274
274
|
args.keyID,
|
|
@@ -285,4 +285,4 @@ export class ProtoWallet implements ProtoWalletApi {
|
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
287
|
|
|
288
|
-
export default ProtoWallet
|
|
288
|
+
export default ProtoWallet
|
|
@@ -295,7 +295,6 @@ export interface SendWithResult {
|
|
|
295
295
|
status: SendWithResultStatus
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
-
|
|
299
298
|
export interface SignableTransaction {
|
|
300
299
|
tx: AtomicBEEF
|
|
301
300
|
reference: Base64String
|
|
@@ -366,7 +365,7 @@ export interface SignActionArgs {
|
|
|
366
365
|
}
|
|
367
366
|
|
|
368
367
|
/**
|
|
369
|
-
*
|
|
368
|
+
*
|
|
370
369
|
*/
|
|
371
370
|
export interface SignActionResult {
|
|
372
371
|
txid?: TXIDHexString
|
|
@@ -580,9 +579,9 @@ export interface WalletEncryptionArgs {
|
|
|
580
579
|
|
|
581
580
|
/**
|
|
582
581
|
* When `identityKey` is true, `WalletEncryptionArgs` are not used.
|
|
583
|
-
*
|
|
582
|
+
*
|
|
584
583
|
* When `identityKey` is undefined, `WalletEncryptionArgs` are required.
|
|
585
|
-
*
|
|
584
|
+
*
|
|
586
585
|
* @param {BooleanDefaultFalse|true} [identityKey] - Use true to retrieve the current user's own identity key, overriding any protocol ID, key ID, or counterparty specified.
|
|
587
586
|
* @param {BooleanDefaultFalse} [forSelf] - Whether to return the public key derived from the current user's own identity (as opposed to the counterparty's identity).
|
|
588
587
|
*/
|
|
@@ -910,7 +909,7 @@ export interface WalletErrorObject extends Error {
|
|
|
910
909
|
}
|
|
911
910
|
|
|
912
911
|
/**
|
|
913
|
-
*
|
|
912
|
+
*
|
|
914
913
|
*/
|
|
915
914
|
export interface GetPublicKeyResult {
|
|
916
915
|
publicKey: PubKeyHex
|
|
@@ -921,7 +920,7 @@ export interface GetPublicKeyResult {
|
|
|
921
920
|
* key derivation, encryption, decryption, hmac creation and verification, signature generation and verification
|
|
922
921
|
*
|
|
923
922
|
* Error Handling
|
|
924
|
-
*
|
|
923
|
+
*
|
|
925
924
|
* Every method of the `Wallet` interface has a return value of the form `Promise<object>`.
|
|
926
925
|
* When an error occurs, an exception object may be thrown which must conform to the `WalletErrorObject` interface.
|
|
927
926
|
* Serialization layers can rely on the `isError` property being unique to error objects to
|
|
@@ -1043,9 +1042,9 @@ export interface ProtoWalletApi {
|
|
|
1043
1042
|
* encryption, decryption, identity certificate management, identity verification, and communication
|
|
1044
1043
|
* with applications as per the BRC standards. This interface allows applications to interact with
|
|
1045
1044
|
* the wallet for a range of functionalities aligned with the Babbage architectural principles.
|
|
1046
|
-
*
|
|
1045
|
+
*
|
|
1047
1046
|
* Error Handling
|
|
1048
|
-
*
|
|
1047
|
+
*
|
|
1049
1048
|
* Every method of the `Wallet` interface has a return value of the form `Promise<object>`.
|
|
1050
1049
|
* When an error occurs, an exception object may be thrown which must conform to the `WalletErrorObject` interface.
|
|
1051
1050
|
* Serialization layers can rely on the `isError` property being unique to error objects to
|
|
@@ -1281,4 +1280,4 @@ export interface Wallet extends ProtoWalletApi {
|
|
|
1281
1280
|
args: {},
|
|
1282
1281
|
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
1283
1282
|
) => Promise<GetVersionResult>
|
|
1284
|
-
}
|
|
1283
|
+
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { AcquireCertificateArgs, AcquireCertificateResult, Base64String, BasketStringUnder300Bytes, BEEF, BooleanDefaultFalse, BooleanDefaultTrue, Byte, CertificateFieldNameUnder50Bytes, CreateActionArgs, CreateActionResult, DescriptionString5to50Bytes, DiscoverCertificatesResult, EntityIconURLStringMax500Bytes, EntityNameStringMax100Bytes, HexString, InternalizeActionArgs, ISOTimestampString, KeyIDStringUnder800Bytes, LabelStringUnder300Bytes, ListActionsArgs, ListActionsResult, ListCertificatesResult, ListOutputsArgs, ListOutputsResult, OriginatorDomainNameStringUnder250Bytes, OutpointString, OutputTagStringUnder300Bytes, PositiveInteger, PositiveIntegerDefault10Max10000, PositiveIntegerMax10, PositiveIntegerOrZero, ProtocolString5To400Bytes, ProveCertificateArgs, ProveCertificateResult, PubKeyHex, SatoshiValue, SecurityLevel, SignActionArgs, SignActionResult, TXIDHexString, VersionString7To30Bytes, Wallet } from './Wallet.interfaces.js'
|
|
1
|
+
import { AcquireCertificateArgs, AcquireCertificateResult, Base64String, BasketStringUnder300Bytes, BEEF, BooleanDefaultFalse, BooleanDefaultTrue, Byte, CertificateFieldNameUnder50Bytes, CreateActionArgs, CreateActionResult, DescriptionString5to50Bytes, DiscoverCertificatesResult, EntityIconURLStringMax500Bytes, EntityNameStringMax100Bytes, HexString, InternalizeActionArgs, ISOTimestampString, KeyIDStringUnder800Bytes, LabelStringUnder300Bytes, ListActionsArgs, ListActionsResult, ListCertificatesResult, ListOutputsArgs, ListOutputsResult, OriginatorDomainNameStringUnder250Bytes, OutpointString, OutputTagStringUnder300Bytes, PositiveInteger, PositiveIntegerDefault10Max10000, PositiveIntegerMax10, PositiveIntegerOrZero, ProtocolString5To400Bytes, ProveCertificateArgs, ProveCertificateResult, PubKeyHex, SatoshiValue, SecurityLevel, SignActionArgs, SignActionResult, TXIDHexString, VersionString7To30Bytes, Wallet, AuthenticatedResult } from './Wallet.interfaces.js'
|
|
2
2
|
import WindowCWISubstrate from './substrates/window.CWI.js'
|
|
3
3
|
import XDMSubstrate from './substrates/XDM.js'
|
|
4
4
|
import WalletWireTransceiver from './substrates/WalletWireTransceiver.js'
|
|
5
5
|
import HTTPWalletWire from './substrates/HTTPWalletWire.js'
|
|
6
6
|
import HTTPWalletJSON from './substrates/HTTPWalletJSON.js'
|
|
7
|
-
import { AuthenticatedResult } from './Wallet.interfaces.js'
|
|
8
7
|
|
|
9
8
|
const MAX_XDM_RESPONSE_WAIT = 200
|
|
10
9
|
|
|
@@ -79,8 +79,8 @@ describe('KeyDeriver', () => {
|
|
|
79
79
|
expect(derivedSymmetricKey.toHex()).toEqual(new SymmetricKey(priv.deriveSharedSecret(pub).x?.toArray()).toHex())
|
|
80
80
|
})
|
|
81
81
|
|
|
82
|
-
test('should
|
|
83
|
-
expect(() => keyDeriver.deriveSymmetricKey(protocolID, keyID, 'anyone')).toThrow()
|
|
82
|
+
test('should be able to derive symmetric key with anyone', () => {
|
|
83
|
+
expect(() => keyDeriver.deriveSymmetricKey(protocolID, keyID, 'anyone')).not.toThrow()
|
|
84
84
|
})
|
|
85
85
|
|
|
86
86
|
test('should reveal the correct counterparty shared secret', () => {
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createMasterCertificate = createMasterCertificate;
|
|
4
|
-
exports.createVerifiableCertificate = createVerifiableCertificate;
|
|
5
|
-
const mod_js_1 = require("../../../mod.js");
|
|
6
|
-
const MasterCertificate_js_1 = require("../certificates/MasterCertificate.js");
|
|
7
|
-
const VerifiableCertificate_js_1 = require("../certificates/VerifiableCertificate.js");
|
|
8
|
-
/**
|
|
9
|
-
* Creates a Master Certificate by encrypting provided fields and generating a master keyring.
|
|
10
|
-
*
|
|
11
|
-
* @param {ProtoWallet} wallet - The wallet instance used for encryption and public key retrieval.
|
|
12
|
-
* @param {Record<string, string>} fields - The certificate fields to encrypt.
|
|
13
|
-
* @param {string} certificateType - The type of the certificate being created.
|
|
14
|
-
* @param {string} certificateSerialNumber - The serial number of the certificate.
|
|
15
|
-
* @param {string} certifierPublicKey - The public key of the certifier.
|
|
16
|
-
* @returns {Promise<MasterCertificate>} A promise resolving to the created Master Certificate.
|
|
17
|
-
*/
|
|
18
|
-
async function createMasterCertificate(wallet, fields, certificateType, certificateSerialNumber, certifierPublicKey) {
|
|
19
|
-
const certificateFields = {};
|
|
20
|
-
const masterKeyring = {};
|
|
21
|
-
for (const fieldName in fields) {
|
|
22
|
-
const fieldSymmetricKey = mod_js_1.SymmetricKey.fromRandom();
|
|
23
|
-
const encryptedFieldValue = fieldSymmetricKey.encrypt(mod_js_1.Utils.toArray(fields[fieldName], 'utf8'));
|
|
24
|
-
certificateFields[fieldName] = mod_js_1.Utils.toBase64(encryptedFieldValue);
|
|
25
|
-
const encryptedFieldKey = await wallet.encrypt({
|
|
26
|
-
plaintext: fieldSymmetricKey.toArray(),
|
|
27
|
-
protocolID: [2, 'certificate field encryption'],
|
|
28
|
-
keyID: `${certificateSerialNumber} ${fieldName}`,
|
|
29
|
-
counterparty: 'self'
|
|
30
|
-
});
|
|
31
|
-
masterKeyring[fieldName] = mod_js_1.Utils.toBase64(encryptedFieldKey.ciphertext);
|
|
32
|
-
}
|
|
33
|
-
return new MasterCertificate_js_1.MasterCertificate(certificateType, certificateSerialNumber, (await wallet.getPublicKey({ identityKey: true })).publicKey, certifierPublicKey, 'revocationOutpoint', certificateFields, masterKeyring);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Creates a Verifiable Certificate by signing a Master Certificate and generating a keyring for a verifier.
|
|
37
|
-
*
|
|
38
|
-
* @param {MasterCertificate} masterCertificate - The master certificate to convert into a verifiable certificate.
|
|
39
|
-
* @param {ProtoWallet} wallet - The wallet instance used for generating a keyring for the verifier.
|
|
40
|
-
* @param {string} verifierIdentityKey - The identity key of the verifier.
|
|
41
|
-
* @param {string[]} fieldsToReveal - The list of fields to reveal to the verifier.
|
|
42
|
-
* @param {PrivateKey} certifierPrivateKey - The private key of the certifier for signing the certificate.
|
|
43
|
-
* @returns {Promise<VerifiableCertificate>} A promise resolving to the created Verifiable Certificate.
|
|
44
|
-
*/
|
|
45
|
-
async function createVerifiableCertificate(masterCertificate, wallet, verifierIdentityKey, fieldsToReveal, certifierPrivateKey) {
|
|
46
|
-
const certifierWallet = new mod_js_1.ProtoWallet(certifierPrivateKey);
|
|
47
|
-
await masterCertificate.sign(certifierWallet);
|
|
48
|
-
const keyringForVerifier = await masterCertificate.createKeyringForVerifier(wallet, verifierIdentityKey, fieldsToReveal);
|
|
49
|
-
return new VerifiableCertificate_js_1.VerifiableCertificate(masterCertificate.type, masterCertificate.serialNumber, masterCertificate.subject, masterCertificate.certifier, masterCertificate.revocationOutpoint, masterCertificate.fields, masterCertificate.signature, keyringForVerifier);
|
|
50
|
-
}
|
|
51
|
-
//# sourceMappingURL=certificateHelpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"certificateHelpers.js","sourceRoot":"","sources":["../../../../../src/auth/utils/certificateHelpers.ts"],"names":[],"mappings":";;AAcA,0DAiCC;AAYD,kEA0BC;AArFD,4CAA8E;AAC9E,+EAAwE;AACxE,uFAAgF;AAEhF;;;;;;;;;GASG;AACI,KAAK,UAAU,uBAAuB,CAC3C,MAAmB,EACnB,MAA8B,EAC9B,eAAuB,EACvB,uBAA+B,EAC/B,kBAA0B;IAE1B,MAAM,iBAAiB,GAA2B,EAAE,CAAA;IACpD,MAAM,aAAa,GAA2B,EAAE,CAAA;IAEhD,KAAK,MAAM,SAAS,IAAI,MAAM,EAAE,CAAC;QAC/B,MAAM,iBAAiB,GAAG,qBAAY,CAAC,UAAU,EAAE,CAAA;QACnD,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,OAAO,CAAC,cAAK,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,CAAC,CAAA;QAC/F,iBAAiB,CAAC,SAAS,CAAC,GAAG,cAAK,CAAC,QAAQ,CAAC,mBAA+B,CAAC,CAAA;QAE9E,MAAM,iBAAiB,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;YAC7C,SAAS,EAAE,iBAAiB,CAAC,OAAO,EAAE;YACtC,UAAU,EAAE,CAAC,CAAC,EAAE,8BAA8B,CAAC;YAC/C,KAAK,EAAE,GAAG,uBAAuB,IAAI,SAAS,EAAE;YAChD,YAAY,EAAE,MAAM;SACrB,CAAC,CAAA;QACF,aAAa,CAAC,SAAS,CAAC,GAAG,cAAK,CAAC,QAAQ,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAA;IACzE,CAAC;IAED,OAAO,IAAI,wCAAiB,CAC1B,eAAe,EACf,uBAAuB,EACvB,CAAC,MAAM,MAAM,CAAC,YAAY,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,EAC5D,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,CACd,CAAA;AACH,CAAC;AAED;;;;;;;;;GASG;AACI,KAAK,UAAU,2BAA2B,CAC/C,iBAAoC,EACpC,MAAmB,EACnB,mBAA2B,EAC3B,cAAwB,EACxB,mBAA+B;IAE/B,MAAM,eAAe,GAAG,IAAI,oBAAW,CAAC,mBAAmB,CAAC,CAAA;IAC5D,MAAM,iBAAiB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;IAE7C,MAAM,kBAAkB,GAAG,MAAM,iBAAiB,CAAC,wBAAwB,CACzE,MAAM,EACN,mBAAmB,EACnB,cAAc,CACf,CAAA;IAED,OAAO,IAAI,gDAAqB,CAC9B,iBAAiB,CAAC,IAAI,EACtB,iBAAiB,CAAC,YAAY,EAC9B,iBAAiB,CAAC,OAAO,EACzB,iBAAiB,CAAC,SAAS,EAC3B,iBAAiB,CAAC,kBAAkB,EACpC,iBAAiB,CAAC,MAAM,EACxB,iBAAiB,CAAC,SAAS,EAC3B,kBAAkB,CACnB,CAAA;AACH,CAAC"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { SymmetricKey, Utils, ProtoWallet } from "../../../mod.js";
|
|
2
|
-
import { MasterCertificate } from "../certificates/MasterCertificate.js";
|
|
3
|
-
import { VerifiableCertificate } from "../certificates/VerifiableCertificate.js";
|
|
4
|
-
/**
|
|
5
|
-
* Creates a Master Certificate by encrypting provided fields and generating a master keyring.
|
|
6
|
-
*
|
|
7
|
-
* @param {ProtoWallet} wallet - The wallet instance used for encryption and public key retrieval.
|
|
8
|
-
* @param {Record<string, string>} fields - The certificate fields to encrypt.
|
|
9
|
-
* @param {string} certificateType - The type of the certificate being created.
|
|
10
|
-
* @param {string} certificateSerialNumber - The serial number of the certificate.
|
|
11
|
-
* @param {string} certifierPublicKey - The public key of the certifier.
|
|
12
|
-
* @returns {Promise<MasterCertificate>} A promise resolving to the created Master Certificate.
|
|
13
|
-
*/
|
|
14
|
-
export async function createMasterCertificate(wallet, fields, certificateType, certificateSerialNumber, certifierPublicKey) {
|
|
15
|
-
const certificateFields = {};
|
|
16
|
-
const masterKeyring = {};
|
|
17
|
-
for (const fieldName in fields) {
|
|
18
|
-
const fieldSymmetricKey = SymmetricKey.fromRandom();
|
|
19
|
-
const encryptedFieldValue = fieldSymmetricKey.encrypt(Utils.toArray(fields[fieldName], 'utf8'));
|
|
20
|
-
certificateFields[fieldName] = Utils.toBase64(encryptedFieldValue);
|
|
21
|
-
const encryptedFieldKey = await wallet.encrypt({
|
|
22
|
-
plaintext: fieldSymmetricKey.toArray(),
|
|
23
|
-
protocolID: [2, 'certificate field encryption'],
|
|
24
|
-
keyID: `${certificateSerialNumber} ${fieldName}`,
|
|
25
|
-
counterparty: 'self'
|
|
26
|
-
});
|
|
27
|
-
masterKeyring[fieldName] = Utils.toBase64(encryptedFieldKey.ciphertext);
|
|
28
|
-
}
|
|
29
|
-
return new MasterCertificate(certificateType, certificateSerialNumber, (await wallet.getPublicKey({ identityKey: true })).publicKey, certifierPublicKey, 'revocationOutpoint', certificateFields, masterKeyring);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Creates a Verifiable Certificate by signing a Master Certificate and generating a keyring for a verifier.
|
|
33
|
-
*
|
|
34
|
-
* @param {MasterCertificate} masterCertificate - The master certificate to convert into a verifiable certificate.
|
|
35
|
-
* @param {ProtoWallet} wallet - The wallet instance used for generating a keyring for the verifier.
|
|
36
|
-
* @param {string} verifierIdentityKey - The identity key of the verifier.
|
|
37
|
-
* @param {string[]} fieldsToReveal - The list of fields to reveal to the verifier.
|
|
38
|
-
* @param {PrivateKey} certifierPrivateKey - The private key of the certifier for signing the certificate.
|
|
39
|
-
* @returns {Promise<VerifiableCertificate>} A promise resolving to the created Verifiable Certificate.
|
|
40
|
-
*/
|
|
41
|
-
export async function createVerifiableCertificate(masterCertificate, wallet, verifierIdentityKey, fieldsToReveal, certifierPrivateKey) {
|
|
42
|
-
const certifierWallet = new ProtoWallet(certifierPrivateKey);
|
|
43
|
-
await masterCertificate.sign(certifierWallet);
|
|
44
|
-
const keyringForVerifier = await masterCertificate.createKeyringForVerifier(wallet, verifierIdentityKey, fieldsToReveal);
|
|
45
|
-
return new VerifiableCertificate(masterCertificate.type, masterCertificate.serialNumber, masterCertificate.subject, masterCertificate.certifier, masterCertificate.revocationOutpoint, masterCertificate.fields, masterCertificate.signature, keyringForVerifier);
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=certificateHelpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"certificateHelpers.js","sourceRoot":"","sources":["../../../../../src/auth/utils/certificateHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAA;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAA;AAEhF;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,MAAmB,EACnB,MAA8B,EAC9B,eAAuB,EACvB,uBAA+B,EAC/B,kBAA0B;IAE1B,MAAM,iBAAiB,GAA2B,EAAE,CAAA;IACpD,MAAM,aAAa,GAA2B,EAAE,CAAA;IAEhD,KAAK,MAAM,SAAS,IAAI,MAAM,EAAE,CAAC;QAC/B,MAAM,iBAAiB,GAAG,YAAY,CAAC,UAAU,EAAE,CAAA;QACnD,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,CAAC,CAAA;QAC/F,iBAAiB,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,mBAA+B,CAAC,CAAA;QAE9E,MAAM,iBAAiB,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;YAC7C,SAAS,EAAE,iBAAiB,CAAC,OAAO,EAAE;YACtC,UAAU,EAAE,CAAC,CAAC,EAAE,8BAA8B,CAAC;YAC/C,KAAK,EAAE,GAAG,uBAAuB,IAAI,SAAS,EAAE;YAChD,YAAY,EAAE,MAAM;SACrB,CAAC,CAAA;QACF,aAAa,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAA;IACzE,CAAC;IAED,OAAO,IAAI,iBAAiB,CAC1B,eAAe,EACf,uBAAuB,EACvB,CAAC,MAAM,MAAM,CAAC,YAAY,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,EAC5D,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,CACd,CAAA;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,iBAAoC,EACpC,MAAmB,EACnB,mBAA2B,EAC3B,cAAwB,EACxB,mBAA+B;IAE/B,MAAM,eAAe,GAAG,IAAI,WAAW,CAAC,mBAAmB,CAAC,CAAA;IAC5D,MAAM,iBAAiB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;IAE7C,MAAM,kBAAkB,GAAG,MAAM,iBAAiB,CAAC,wBAAwB,CACzE,MAAM,EACN,mBAAmB,EACnB,cAAc,CACf,CAAA;IAED,OAAO,IAAI,qBAAqB,CAC9B,iBAAiB,CAAC,IAAI,EACtB,iBAAiB,CAAC,YAAY,EAC9B,iBAAiB,CAAC,OAAO,EACzB,iBAAiB,CAAC,SAAS,EAC3B,iBAAiB,CAAC,kBAAkB,EACpC,iBAAiB,CAAC,MAAM,EACxB,iBAAiB,CAAC,SAAS,EAC3B,kBAAkB,CACnB,CAAA;AACH,CAAC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { PrivateKey, ProtoWallet } from "../../../mod.js";
|
|
2
|
-
import { MasterCertificate } from "../certificates/MasterCertificate.js";
|
|
3
|
-
import { VerifiableCertificate } from "../certificates/VerifiableCertificate.js";
|
|
4
|
-
/**
|
|
5
|
-
* Creates a Master Certificate by encrypting provided fields and generating a master keyring.
|
|
6
|
-
*
|
|
7
|
-
* @param {ProtoWallet} wallet - The wallet instance used for encryption and public key retrieval.
|
|
8
|
-
* @param {Record<string, string>} fields - The certificate fields to encrypt.
|
|
9
|
-
* @param {string} certificateType - The type of the certificate being created.
|
|
10
|
-
* @param {string} certificateSerialNumber - The serial number of the certificate.
|
|
11
|
-
* @param {string} certifierPublicKey - The public key of the certifier.
|
|
12
|
-
* @returns {Promise<MasterCertificate>} A promise resolving to the created Master Certificate.
|
|
13
|
-
*/
|
|
14
|
-
export declare function createMasterCertificate(wallet: ProtoWallet, fields: Record<string, string>, certificateType: string, certificateSerialNumber: string, certifierPublicKey: string): Promise<MasterCertificate>;
|
|
15
|
-
/**
|
|
16
|
-
* Creates a Verifiable Certificate by signing a Master Certificate and generating a keyring for a verifier.
|
|
17
|
-
*
|
|
18
|
-
* @param {MasterCertificate} masterCertificate - The master certificate to convert into a verifiable certificate.
|
|
19
|
-
* @param {ProtoWallet} wallet - The wallet instance used for generating a keyring for the verifier.
|
|
20
|
-
* @param {string} verifierIdentityKey - The identity key of the verifier.
|
|
21
|
-
* @param {string[]} fieldsToReveal - The list of fields to reveal to the verifier.
|
|
22
|
-
* @param {PrivateKey} certifierPrivateKey - The private key of the certifier for signing the certificate.
|
|
23
|
-
* @returns {Promise<VerifiableCertificate>} A promise resolving to the created Verifiable Certificate.
|
|
24
|
-
*/
|
|
25
|
-
export declare function createVerifiableCertificate(masterCertificate: MasterCertificate, wallet: ProtoWallet, verifierIdentityKey: string, fieldsToReveal: string[], certifierPrivateKey: PrivateKey): Promise<VerifiableCertificate>;
|
|
26
|
-
//# sourceMappingURL=certificateHelpers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"certificateHelpers.d.ts","sourceRoot":"","sources":["../../../../../src/auth/utils/certificateHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAuB,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAA;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAA;AAEhF;;;;;;;;;GASG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,eAAe,EAAE,MAAM,EACvB,uBAAuB,EAAE,MAAM,EAC/B,kBAAkB,EAAE,MAAM,GACzB,OAAO,CAAC,iBAAiB,CAAC,CA2B5B;AAED;;;;;;;;;GASG;AACH,wBAAsB,2BAA2B,CAC/C,iBAAiB,EAAE,iBAAiB,EACpC,MAAM,EAAE,WAAW,EACnB,mBAAmB,EAAE,MAAM,EAC3B,cAAc,EAAE,MAAM,EAAE,EACxB,mBAAmB,EAAE,UAAU,GAC9B,OAAO,CAAC,qBAAqB,CAAC,CAoBhC"}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { PrivateKey, SymmetricKey, Utils, ProtoWallet } from "../../../mod.js"
|
|
2
|
-
import { MasterCertificate } from "../certificates/MasterCertificate.js"
|
|
3
|
-
import { VerifiableCertificate } from "../certificates/VerifiableCertificate.js"
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Creates a Master Certificate by encrypting provided fields and generating a master keyring.
|
|
7
|
-
*
|
|
8
|
-
* @param {ProtoWallet} wallet - The wallet instance used for encryption and public key retrieval.
|
|
9
|
-
* @param {Record<string, string>} fields - The certificate fields to encrypt.
|
|
10
|
-
* @param {string} certificateType - The type of the certificate being created.
|
|
11
|
-
* @param {string} certificateSerialNumber - The serial number of the certificate.
|
|
12
|
-
* @param {string} certifierPublicKey - The public key of the certifier.
|
|
13
|
-
* @returns {Promise<MasterCertificate>} A promise resolving to the created Master Certificate.
|
|
14
|
-
*/
|
|
15
|
-
export async function createMasterCertificate(
|
|
16
|
-
wallet: ProtoWallet,
|
|
17
|
-
fields: Record<string, string>,
|
|
18
|
-
certificateType: string,
|
|
19
|
-
certificateSerialNumber: string,
|
|
20
|
-
certifierPublicKey: string
|
|
21
|
-
): Promise<MasterCertificate> {
|
|
22
|
-
const certificateFields: Record<string, string> = {}
|
|
23
|
-
const masterKeyring: Record<string, string> = {}
|
|
24
|
-
|
|
25
|
-
for (const fieldName in fields) {
|
|
26
|
-
const fieldSymmetricKey = SymmetricKey.fromRandom()
|
|
27
|
-
const encryptedFieldValue = fieldSymmetricKey.encrypt(Utils.toArray(fields[fieldName], 'utf8'))
|
|
28
|
-
certificateFields[fieldName] = Utils.toBase64(encryptedFieldValue as number[])
|
|
29
|
-
|
|
30
|
-
const encryptedFieldKey = await wallet.encrypt({
|
|
31
|
-
plaintext: fieldSymmetricKey.toArray(),
|
|
32
|
-
protocolID: [2, 'certificate field encryption'],
|
|
33
|
-
keyID: `${certificateSerialNumber} ${fieldName}`,
|
|
34
|
-
counterparty: 'self'
|
|
35
|
-
})
|
|
36
|
-
masterKeyring[fieldName] = Utils.toBase64(encryptedFieldKey.ciphertext)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return new MasterCertificate(
|
|
40
|
-
certificateType,
|
|
41
|
-
certificateSerialNumber,
|
|
42
|
-
(await wallet.getPublicKey({ identityKey: true })).publicKey,
|
|
43
|
-
certifierPublicKey,
|
|
44
|
-
'revocationOutpoint',
|
|
45
|
-
certificateFields,
|
|
46
|
-
masterKeyring
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Creates a Verifiable Certificate by signing a Master Certificate and generating a keyring for a verifier.
|
|
52
|
-
*
|
|
53
|
-
* @param {MasterCertificate} masterCertificate - The master certificate to convert into a verifiable certificate.
|
|
54
|
-
* @param {ProtoWallet} wallet - The wallet instance used for generating a keyring for the verifier.
|
|
55
|
-
* @param {string} verifierIdentityKey - The identity key of the verifier.
|
|
56
|
-
* @param {string[]} fieldsToReveal - The list of fields to reveal to the verifier.
|
|
57
|
-
* @param {PrivateKey} certifierPrivateKey - The private key of the certifier for signing the certificate.
|
|
58
|
-
* @returns {Promise<VerifiableCertificate>} A promise resolving to the created Verifiable Certificate.
|
|
59
|
-
*/
|
|
60
|
-
export async function createVerifiableCertificate(
|
|
61
|
-
masterCertificate: MasterCertificate,
|
|
62
|
-
wallet: ProtoWallet,
|
|
63
|
-
verifierIdentityKey: string,
|
|
64
|
-
fieldsToReveal: string[],
|
|
65
|
-
certifierPrivateKey: PrivateKey
|
|
66
|
-
): Promise<VerifiableCertificate> {
|
|
67
|
-
const certifierWallet = new ProtoWallet(certifierPrivateKey)
|
|
68
|
-
await masterCertificate.sign(certifierWallet)
|
|
69
|
-
|
|
70
|
-
const keyringForVerifier = await masterCertificate.createKeyringForVerifier(
|
|
71
|
-
wallet,
|
|
72
|
-
verifierIdentityKey,
|
|
73
|
-
fieldsToReveal
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
return new VerifiableCertificate(
|
|
77
|
-
masterCertificate.type,
|
|
78
|
-
masterCertificate.serialNumber,
|
|
79
|
-
masterCertificate.subject,
|
|
80
|
-
masterCertificate.certifier,
|
|
81
|
-
masterCertificate.revocationOutpoint,
|
|
82
|
-
masterCertificate.fields,
|
|
83
|
-
masterCertificate.signature,
|
|
84
|
-
keyringForVerifier
|
|
85
|
-
)
|
|
86
|
-
}
|