@bsv/sdk 1.3.11 → 1.3.12
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/certificates/Certificate.js.map +1 -1
- package/dist/cjs/src/auth/certificates/MasterCertificate.js +8 -8
- package/dist/cjs/src/auth/certificates/MasterCertificate.js.map +1 -1
- package/dist/cjs/src/auth/certificates/VerifiableCertificate.js +1 -1
- package/dist/cjs/src/auth/certificates/VerifiableCertificate.js.map +1 -1
- package/dist/cjs/src/wallet/ProtoWallet.js +9 -9
- package/dist/cjs/src/wallet/ProtoWallet.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/auth/certificates/Certificate.js.map +1 -1
- package/dist/esm/src/auth/certificates/MasterCertificate.js +8 -8
- package/dist/esm/src/auth/certificates/MasterCertificate.js.map +1 -1
- package/dist/esm/src/auth/certificates/VerifiableCertificate.js +1 -1
- package/dist/esm/src/auth/certificates/VerifiableCertificate.js.map +1 -1
- package/dist/esm/src/wallet/ProtoWallet.js +9 -9
- package/dist/esm/src/wallet/ProtoWallet.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/auth/certificates/Certificate.d.ts +2 -2
- package/dist/types/src/auth/certificates/Certificate.d.ts.map +1 -1
- package/dist/types/src/auth/certificates/MasterCertificate.d.ts +10 -10
- package/dist/types/src/auth/certificates/MasterCertificate.d.ts.map +1 -1
- package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts +3 -3
- package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts.map +1 -1
- package/dist/types/src/wallet/ProtoWallet.d.ts +12 -12
- package/dist/types/src/wallet/ProtoWallet.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/docs/auth.md +27 -23
- package/docs/wallet.md +12 -12
- package/package.json +1 -1
- package/src/auth/certificates/Certificate.ts +1 -2
- package/src/auth/certificates/MasterCertificate.ts +18 -15
- package/src/auth/certificates/VerifiableCertificate.ts +3 -3
- package/src/auth/certificates/__tests/VerifiableCertificate.test.ts +29 -0
- package/src/wallet/ProtoWallet.ts +20 -11
package/docs/auth.md
CHANGED
|
@@ -218,15 +218,15 @@ export default class Certificate {
|
|
|
218
218
|
toBinary(includeSignature: boolean = true): number[]
|
|
219
219
|
static fromBinary(bin: number[]): Certificate
|
|
220
220
|
async verify(): Promise<boolean>
|
|
221
|
-
async sign(certifierWallet:
|
|
222
|
-
static getCertificateFieldEncryptionDetails(
|
|
221
|
+
async sign(certifierWallet: ProtoWallet): Promise<void>
|
|
222
|
+
static getCertificateFieldEncryptionDetails(fieldName: string, serialNumber?: string): {
|
|
223
223
|
protocolID: WalletProtocol;
|
|
224
224
|
keyID: string;
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
```
|
|
228
228
|
|
|
229
|
-
See also: [Base64String](#type-base64string), [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes), [HexString](#type-hexstring), [OutpointString](#type-outpointstring), [
|
|
229
|
+
See also: [Base64String](#type-base64string), [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes), [HexString](#type-hexstring), [OutpointString](#type-outpointstring), [ProtoWallet](#class-protowallet), [PubKeyHex](#type-pubkeyhex), [WalletProtocol](#type-walletprotocol), [sign](#variable-sign), [verify](#variable-verify)
|
|
230
230
|
|
|
231
231
|
<details>
|
|
232
232
|
|
|
@@ -344,7 +344,7 @@ Argument Details
|
|
|
344
344
|
Helper function which retrieves the protocol ID and key ID for certificate field encryption.
|
|
345
345
|
|
|
346
346
|
```ts
|
|
347
|
-
static getCertificateFieldEncryptionDetails(
|
|
347
|
+
static getCertificateFieldEncryptionDetails(fieldName: string, serialNumber?: string): {
|
|
348
348
|
protocolID: WalletProtocol;
|
|
349
349
|
keyID: string;
|
|
350
350
|
}
|
|
@@ -369,9 +369,9 @@ Argument Details
|
|
|
369
369
|
Signs the certificate using the provided certifier wallet.
|
|
370
370
|
|
|
371
371
|
```ts
|
|
372
|
-
async sign(certifierWallet:
|
|
372
|
+
async sign(certifierWallet: ProtoWallet): Promise<void>
|
|
373
373
|
```
|
|
374
|
-
See also: [
|
|
374
|
+
See also: [ProtoWallet](#class-protowallet)
|
|
375
375
|
|
|
376
376
|
Argument Details
|
|
377
377
|
|
|
@@ -466,14 +466,18 @@ export class MasterCertificate extends Certificate {
|
|
|
466
466
|
declare signature?: HexString;
|
|
467
467
|
masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>;
|
|
468
468
|
constructor(type: Base64String, serialNumber: Base64String, subject: PubKeyHex, certifier: PubKeyHex, revocationOutpoint: OutpointString, fields: Record<CertificateFieldNameUnder50Bytes, Base64String>, masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>, signature?: HexString)
|
|
469
|
-
static async createCertificateFields(creatorWallet:
|
|
470
|
-
static async createKeyringForVerifier(subjectWallet:
|
|
471
|
-
static async issueCertificateForSubject(certifierWallet:
|
|
472
|
-
static async decryptFields(subjectOrCertifierWallet:
|
|
469
|
+
static async createCertificateFields(creatorWallet: ProtoWallet, certifierOrSubject: WalletCounterparty, fields: Record<CertificateFieldNameUnder50Bytes, string>, originator?: OriginatorDomainNameStringUnder250Bytes): Promise<CreateCertificateFieldsResult>
|
|
470
|
+
static async createKeyringForVerifier(subjectWallet: ProtoWallet, certifier: WalletCounterparty, verifier: WalletCounterparty, fields: Record<CertificateFieldNameUnder50Bytes, Base64String>, fieldsToReveal: string[], masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>, serialNumber: Base64String, originator?: OriginatorDomainNameStringUnder250Bytes): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
|
|
471
|
+
static async issueCertificateForSubject(certifierWallet: ProtoWallet, subject: WalletCounterparty, fields: Record<CertificateFieldNameUnder50Bytes, string>, certificateType: string, getRevocationOutpoint = async (serialNumber: string): Promise<string> => { return "Certificate revocation not tracked."; }, serialNumber?: string): Promise<MasterCertificate>
|
|
472
|
+
static async decryptFields(subjectOrCertifierWallet: ProtoWallet, masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>, fields: Record<CertificateFieldNameUnder50Bytes, Base64String>, counterparty: WalletCounterparty): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
|
|
473
|
+
static async decryptField(subjectOrCertifierWallet: ProtoWallet, masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>, fieldName: Base64String, fieldValue: Base64String, counterparty: WalletCounterparty, originator?: OriginatorDomainNameStringUnder250Bytes): Promise<{
|
|
474
|
+
fieldRevelationKey: number[];
|
|
475
|
+
decryptedFieldValue: string;
|
|
476
|
+
}>
|
|
473
477
|
}
|
|
474
478
|
```
|
|
475
479
|
|
|
476
|
-
See also: [Base64String](#type-base64string), [Certificate](#class-certificate), [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes), [HexString](#type-hexstring), [OutpointString](#type-outpointstring), [
|
|
480
|
+
See also: [Base64String](#type-base64string), [Certificate](#class-certificate), [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes), [HexString](#type-hexstring), [OriginatorDomainNameStringUnder250Bytes](#type-originatordomainnamestringunder250bytes), [OutpointString](#type-outpointstring), [ProtoWallet](#class-protowallet), [PubKeyHex](#type-pubkeyhex), [WalletCounterparty](#type-walletcounterparty)
|
|
477
481
|
|
|
478
482
|
<details>
|
|
479
483
|
|
|
@@ -486,9 +490,9 @@ This method returns a master keyring tied to a specific certifier or subject who
|
|
|
486
490
|
and sign off on the fields, along with the encrypted certificate fields.
|
|
487
491
|
|
|
488
492
|
```ts
|
|
489
|
-
static async createCertificateFields(creatorWallet:
|
|
493
|
+
static async createCertificateFields(creatorWallet: ProtoWallet, certifierOrSubject: WalletCounterparty, fields: Record<CertificateFieldNameUnder50Bytes, string>, originator?: OriginatorDomainNameStringUnder250Bytes): Promise<CreateCertificateFieldsResult>
|
|
490
494
|
```
|
|
491
|
-
See also: [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes), [
|
|
495
|
+
See also: [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes), [OriginatorDomainNameStringUnder250Bytes](#type-originatordomainnamestringunder250bytes), [ProtoWallet](#class-protowallet), [WalletCounterparty](#type-walletcounterparty)
|
|
492
496
|
|
|
493
497
|
Returns
|
|
494
498
|
|
|
@@ -515,9 +519,9 @@ for the verifier's identity key. The result is a keyring containing the keys nec
|
|
|
515
519
|
for the verifier to access the designated fields.
|
|
516
520
|
|
|
517
521
|
```ts
|
|
518
|
-
static async createKeyringForVerifier(subjectWallet:
|
|
522
|
+
static async createKeyringForVerifier(subjectWallet: ProtoWallet, certifier: WalletCounterparty, verifier: WalletCounterparty, fields: Record<CertificateFieldNameUnder50Bytes, Base64String>, fieldsToReveal: string[], masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>, serialNumber: Base64String, originator?: OriginatorDomainNameStringUnder250Bytes): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
|
|
519
523
|
```
|
|
520
|
-
See also: [Base64String](#type-base64string), [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes), [
|
|
524
|
+
See also: [Base64String](#type-base64string), [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes), [OriginatorDomainNameStringUnder250Bytes](#type-originatordomainnamestringunder250bytes), [ProtoWallet](#class-protowallet), [WalletCounterparty](#type-walletcounterparty)
|
|
521
525
|
|
|
522
526
|
Returns
|
|
523
527
|
|
|
@@ -552,9 +556,9 @@ The counterparty used for decryption depends on how the certificate fields were
|
|
|
552
556
|
- Otherwise, the counterparty should always be the other party involved in the certificate issuance process (the subject or certifier).
|
|
553
557
|
|
|
554
558
|
```ts
|
|
555
|
-
static async decryptFields(subjectOrCertifierWallet:
|
|
559
|
+
static async decryptFields(subjectOrCertifierWallet: ProtoWallet, masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>, fields: Record<CertificateFieldNameUnder50Bytes, Base64String>, counterparty: WalletCounterparty): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
|
|
556
560
|
```
|
|
557
|
-
See also: [Base64String](#type-base64string), [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes), [
|
|
561
|
+
See also: [Base64String](#type-base64string), [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes), [ProtoWallet](#class-protowallet), [WalletCounterparty](#type-walletcounterparty)
|
|
558
562
|
|
|
559
563
|
Returns
|
|
560
564
|
|
|
@@ -585,9 +589,9 @@ generated symmetric key, which is then encrypted for the subject. The certificat
|
|
|
585
589
|
can also includes a revocation outpoint to manage potential revocation.
|
|
586
590
|
|
|
587
591
|
```ts
|
|
588
|
-
static async issueCertificateForSubject(certifierWallet:
|
|
592
|
+
static async issueCertificateForSubject(certifierWallet: ProtoWallet, subject: WalletCounterparty, fields: Record<CertificateFieldNameUnder50Bytes, string>, certificateType: string, getRevocationOutpoint = async (serialNumber: string): Promise<string> => { return "Certificate revocation not tracked."; }, serialNumber?: string): Promise<MasterCertificate>
|
|
589
593
|
```
|
|
590
|
-
See also: [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes), [MasterCertificate](#class-mastercertificate), [
|
|
594
|
+
See also: [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes), [MasterCertificate](#class-mastercertificate), [ProtoWallet](#class-protowallet), [WalletCounterparty](#type-walletcounterparty)
|
|
591
595
|
|
|
592
596
|
Returns
|
|
593
597
|
|
|
@@ -1117,11 +1121,11 @@ export class VerifiableCertificate extends Certificate {
|
|
|
1117
1121
|
keyring: Record<CertificateFieldNameUnder50Bytes, string>;
|
|
1118
1122
|
decryptedFields?: Record<CertificateFieldNameUnder50Bytes, Base64String>;
|
|
1119
1123
|
constructor(type: Base64String, serialNumber: Base64String, subject: PubKeyHex, certifier: PubKeyHex, revocationOutpoint: OutpointString, fields: Record<CertificateFieldNameUnder50Bytes, string>, keyring: Record<CertificateFieldNameUnder50Bytes, string>, signature?: HexString, decryptedFields?: Record<CertificateFieldNameUnder50Bytes, Base64String>)
|
|
1120
|
-
async decryptFields(verifierWallet:
|
|
1124
|
+
async decryptFields(verifierWallet: ProtoWallet): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
|
|
1121
1125
|
}
|
|
1122
1126
|
```
|
|
1123
1127
|
|
|
1124
|
-
See also: [Base64String](#type-base64string), [Certificate](#class-certificate), [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes), [HexString](#type-hexstring), [OutpointString](#type-outpointstring), [
|
|
1128
|
+
See also: [Base64String](#type-base64string), [Certificate](#class-certificate), [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes), [HexString](#type-hexstring), [OutpointString](#type-outpointstring), [ProtoWallet](#class-protowallet), [PubKeyHex](#type-pubkeyhex)
|
|
1125
1129
|
|
|
1126
1130
|
<details>
|
|
1127
1131
|
|
|
@@ -1132,9 +1136,9 @@ See also: [Base64String](#type-base64string), [Certificate](#class-certificate),
|
|
|
1132
1136
|
Decrypts selectively revealed certificate fields using the provided keyring and verifier wallet
|
|
1133
1137
|
|
|
1134
1138
|
```ts
|
|
1135
|
-
async decryptFields(verifierWallet:
|
|
1139
|
+
async decryptFields(verifierWallet: ProtoWallet): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
|
|
1136
1140
|
```
|
|
1137
|
-
See also: [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes), [
|
|
1141
|
+
See also: [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes), [ProtoWallet](#class-protowallet)
|
|
1138
1142
|
|
|
1139
1143
|
Returns
|
|
1140
1144
|
|
package/docs/wallet.md
CHANGED
|
@@ -2115,23 +2115,23 @@ enable the management of identity certificates, or store any data. It is also no
|
|
|
2115
2115
|
|
|
2116
2116
|
```ts
|
|
2117
2117
|
export class ProtoWallet {
|
|
2118
|
-
keyDeriver
|
|
2119
|
-
constructor(rootKeyOrKeyDeriver
|
|
2120
|
-
async getPublicKey(args: GetPublicKeyArgs): Promise<{
|
|
2118
|
+
keyDeriver?: KeyDeriverApi;
|
|
2119
|
+
constructor(rootKeyOrKeyDeriver?: PrivateKey | "anyone" | KeyDeriverApi)
|
|
2120
|
+
async getPublicKey(args: GetPublicKeyArgs, originator?: OriginatorDomainNameStringUnder250Bytes): Promise<{
|
|
2121
2121
|
publicKey: PubKeyHex;
|
|
2122
2122
|
}>
|
|
2123
|
-
async revealCounterpartyKeyLinkage(args: RevealCounterpartyKeyLinkageArgs): Promise<RevealCounterpartyKeyLinkageResult>
|
|
2124
|
-
async revealSpecificKeyLinkage(args: RevealSpecificKeyLinkageArgs): Promise<RevealSpecificKeyLinkageResult>
|
|
2125
|
-
async encrypt(args: WalletEncryptArgs): Promise<WalletEncryptResult>
|
|
2126
|
-
async decrypt(args: WalletDecryptArgs): Promise<WalletDecryptResult>
|
|
2127
|
-
async createHmac(args: CreateHmacArgs): Promise<CreateHmacResult>
|
|
2128
|
-
async verifyHmac(args: VerifyHmacArgs): Promise<VerifyHmacResult>
|
|
2129
|
-
async createSignature(args: CreateSignatureArgs): Promise<CreateSignatureResult>
|
|
2130
|
-
async verifySignature(args: VerifySignatureArgs): Promise<VerifySignatureResult>
|
|
2123
|
+
async revealCounterpartyKeyLinkage(args: RevealCounterpartyKeyLinkageArgs, originator?: OriginatorDomainNameStringUnder250Bytes): Promise<RevealCounterpartyKeyLinkageResult>
|
|
2124
|
+
async revealSpecificKeyLinkage(args: RevealSpecificKeyLinkageArgs, originator?: OriginatorDomainNameStringUnder250Bytes): Promise<RevealSpecificKeyLinkageResult>
|
|
2125
|
+
async encrypt(args: WalletEncryptArgs, originator?: OriginatorDomainNameStringUnder250Bytes): Promise<WalletEncryptResult>
|
|
2126
|
+
async decrypt(args: WalletDecryptArgs, originator?: OriginatorDomainNameStringUnder250Bytes): Promise<WalletDecryptResult>
|
|
2127
|
+
async createHmac(args: CreateHmacArgs, originator?: OriginatorDomainNameStringUnder250Bytes): Promise<CreateHmacResult>
|
|
2128
|
+
async verifyHmac(args: VerifyHmacArgs, originator?: OriginatorDomainNameStringUnder250Bytes): Promise<VerifyHmacResult>
|
|
2129
|
+
async createSignature(args: CreateSignatureArgs, originator?: OriginatorDomainNameStringUnder250Bytes): Promise<CreateSignatureResult>
|
|
2130
|
+
async verifySignature(args: VerifySignatureArgs, originator?: OriginatorDomainNameStringUnder250Bytes): Promise<VerifySignatureResult>
|
|
2131
2131
|
}
|
|
2132
2132
|
```
|
|
2133
2133
|
|
|
2134
|
-
See also: [CreateHmacArgs](#interface-createhmacargs), [CreateHmacResult](#interface-createhmacresult), [CreateSignatureArgs](#interface-createsignatureargs), [CreateSignatureResult](#interface-createsignatureresult), [GetPublicKeyArgs](#interface-getpublickeyargs), [KeyDeriverApi](#interface-keyderiverapi), [PrivateKey](#class-privatekey), [PubKeyHex](#type-pubkeyhex), [RevealCounterpartyKeyLinkageArgs](#interface-revealcounterpartykeylinkageargs), [RevealCounterpartyKeyLinkageResult](#interface-revealcounterpartykeylinkageresult), [RevealSpecificKeyLinkageArgs](#interface-revealspecifickeylinkageargs), [RevealSpecificKeyLinkageResult](#interface-revealspecifickeylinkageresult), [VerifyHmacArgs](#interface-verifyhmacargs), [VerifyHmacResult](#interface-verifyhmacresult), [VerifySignatureArgs](#interface-verifysignatureargs), [VerifySignatureResult](#interface-verifysignatureresult), [WalletDecryptArgs](#interface-walletdecryptargs), [WalletDecryptResult](#interface-walletdecryptresult), [WalletEncryptArgs](#interface-walletencryptargs), [WalletEncryptResult](#interface-walletencryptresult), [decrypt](#variable-decrypt), [encrypt](#variable-encrypt)
|
|
2134
|
+
See also: [CreateHmacArgs](#interface-createhmacargs), [CreateHmacResult](#interface-createhmacresult), [CreateSignatureArgs](#interface-createsignatureargs), [CreateSignatureResult](#interface-createsignatureresult), [GetPublicKeyArgs](#interface-getpublickeyargs), [KeyDeriverApi](#interface-keyderiverapi), [OriginatorDomainNameStringUnder250Bytes](#type-originatordomainnamestringunder250bytes), [PrivateKey](#class-privatekey), [PubKeyHex](#type-pubkeyhex), [RevealCounterpartyKeyLinkageArgs](#interface-revealcounterpartykeylinkageargs), [RevealCounterpartyKeyLinkageResult](#interface-revealcounterpartykeylinkageresult), [RevealSpecificKeyLinkageArgs](#interface-revealspecifickeylinkageargs), [RevealSpecificKeyLinkageResult](#interface-revealspecifickeylinkageresult), [VerifyHmacArgs](#interface-verifyhmacargs), [VerifyHmacResult](#interface-verifyhmacresult), [VerifySignatureArgs](#interface-verifysignatureargs), [VerifySignatureResult](#interface-verifysignatureresult), [WalletDecryptArgs](#interface-walletdecryptargs), [WalletDecryptResult](#interface-walletdecryptresult), [WalletEncryptArgs](#interface-walletencryptargs), [WalletEncryptResult](#interface-walletencryptresult), [decrypt](#variable-decrypt), [encrypt](#variable-encrypt)
|
|
2135
2135
|
|
|
2136
2136
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
|
|
2137
2137
|
|
package/package.json
CHANGED
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
HexString,
|
|
6
6
|
OutpointString,
|
|
7
7
|
CertificateFieldNameUnder50Bytes,
|
|
8
|
-
WalletInterface,
|
|
9
8
|
Signature,
|
|
10
9
|
WalletProtocol,
|
|
11
10
|
ProtoWallet
|
|
@@ -232,7 +231,7 @@ export default class Certificate {
|
|
|
232
231
|
* @param {Wallet} certifierWallet - The wallet representing the certifier.
|
|
233
232
|
* @returns {Promise<void>}
|
|
234
233
|
*/
|
|
235
|
-
async sign(certifierWallet:
|
|
234
|
+
async sign(certifierWallet: ProtoWallet): Promise<void> {
|
|
236
235
|
if (this.signature) {
|
|
237
236
|
throw new Error(`Certificate has already been signed! Signature present: ${this.signature}`)
|
|
238
237
|
}
|
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
PubKeyHex,
|
|
9
9
|
Random,
|
|
10
10
|
WalletCounterparty,
|
|
11
|
-
|
|
11
|
+
ProtoWallet,
|
|
12
|
+
OriginatorDomainNameStringUnder250Bytes
|
|
12
13
|
} from '../../../mod.js'
|
|
13
14
|
import Certificate from './Certificate.js'
|
|
14
15
|
|
|
@@ -65,7 +66,7 @@ export class MasterCertificate extends Certificate {
|
|
|
65
66
|
* This method returns a master keyring tied to a specific certifier or subject who will validate
|
|
66
67
|
* and sign off on the fields, along with the encrypted certificate fields.
|
|
67
68
|
*
|
|
68
|
-
* @param {
|
|
69
|
+
* @param {ProtoWallet} creatorWallet - The wallet of the creator responsible for encrypting the fields.
|
|
69
70
|
* @param {WalletCounterparty} certifierOrSubject - The certifier or subject who will validate the certificate fields.
|
|
70
71
|
* @param {Record<CertificateFieldNameUnder50Bytes, string>} fields - A record of certificate field names (under 50 bytes) mapped to their values.
|
|
71
72
|
* @returns {Promise<CreateCertificateFieldsResult>} A promise resolving to an object containing:
|
|
@@ -75,9 +76,10 @@ export class MasterCertificate extends Certificate {
|
|
|
75
76
|
* The master keyring containing encrypted revelation keys for each field.
|
|
76
77
|
*/
|
|
77
78
|
static async createCertificateFields(
|
|
78
|
-
creatorWallet:
|
|
79
|
+
creatorWallet: ProtoWallet,
|
|
79
80
|
certifierOrSubject: WalletCounterparty,
|
|
80
|
-
fields: Record<CertificateFieldNameUnder50Bytes, string
|
|
81
|
+
fields: Record<CertificateFieldNameUnder50Bytes, string>,
|
|
82
|
+
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
81
83
|
): Promise<CreateCertificateFieldsResult> {
|
|
82
84
|
const certificateFields: Record<CertificateFieldNameUnder50Bytes, Base64String> = {}
|
|
83
85
|
const masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String> = {}
|
|
@@ -90,7 +92,7 @@ export class MasterCertificate extends Certificate {
|
|
|
90
92
|
plaintext: fieldSymmetricKey.toArray(),
|
|
91
93
|
...Certificate.getCertificateFieldEncryptionDetails(fieldName), // Only fieldName used on MasterCertificate
|
|
92
94
|
counterparty: certifierOrSubject
|
|
93
|
-
})
|
|
95
|
+
}, originator)
|
|
94
96
|
masterKeyring[fieldName] = Utils.toBase64(encryptedFieldRevelationKey)
|
|
95
97
|
}
|
|
96
98
|
|
|
@@ -106,7 +108,7 @@ export class MasterCertificate extends Certificate {
|
|
|
106
108
|
* for the verifier's identity key. The result is a keyring containing the keys necessary
|
|
107
109
|
* for the verifier to access the designated fields.
|
|
108
110
|
*
|
|
109
|
-
* @param {
|
|
111
|
+
* @param {ProtoWallet} subjectWallet - The wallet instance of the subject, used to decrypt and re-encrypt field keys.
|
|
110
112
|
* @param {WalletCounterparty} verifier - The verifier who will receive access to the selectively revealed fields. Can be an identity key as hex, 'anyone', or 'self'.
|
|
111
113
|
* @param {string[]} fieldsToReveal - An array of field names to be revealed to the verifier. Must be a subset of the certificate's fields.
|
|
112
114
|
* @param {string} [originator] - Optional originator identifier, used if additional context is needed for decryption and encryption operations.
|
|
@@ -117,14 +119,14 @@ export class MasterCertificate extends Certificate {
|
|
|
117
119
|
* - The decrypted master field key fails to decrypt the corresponding field (indicating an invalid key).
|
|
118
120
|
*/
|
|
119
121
|
static async createKeyringForVerifier(
|
|
120
|
-
subjectWallet:
|
|
122
|
+
subjectWallet: ProtoWallet,
|
|
121
123
|
certifier: WalletCounterparty,
|
|
122
124
|
verifier: WalletCounterparty,
|
|
123
125
|
fields: Record<CertificateFieldNameUnder50Bytes, Base64String>,
|
|
124
126
|
fieldsToReveal: string[],
|
|
125
127
|
masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>,
|
|
126
128
|
serialNumber: Base64String,
|
|
127
|
-
originator?:
|
|
129
|
+
originator?: OriginatorDomainNameStringUnder250Bytes): Promise<Record<CertificateFieldNameUnder50Bytes, string>> {
|
|
128
130
|
if (!Array.isArray(fieldsToReveal)) {
|
|
129
131
|
throw new Error('fieldsToReveal must be an array of strings')
|
|
130
132
|
}
|
|
@@ -161,7 +163,7 @@ export class MasterCertificate extends Certificate {
|
|
|
161
163
|
* generated symmetric key, which is then encrypted for the subject. The certificate
|
|
162
164
|
* can also includes a revocation outpoint to manage potential revocation.
|
|
163
165
|
*
|
|
164
|
-
* @param {
|
|
166
|
+
* @param {ProtoWallet} certifierWallet - The wallet of the certifier, used to sign the certificate and encrypt field keys.
|
|
165
167
|
* @param {WalletCounterparty} subject - The subject for whom the certificate is issued.
|
|
166
168
|
* @param {Record<CertificateFieldNameUnder50Bytes, string>} fields - Unencrypted certificate fields to include, with their names and values.
|
|
167
169
|
* @param {string} certificateType - The type of certificate being issued.
|
|
@@ -173,7 +175,7 @@ export class MasterCertificate extends Certificate {
|
|
|
173
175
|
* @throws {Error} Throws an error if any operation (e.g., encryption, signing) fails during certificate issuance.
|
|
174
176
|
*/
|
|
175
177
|
static async issueCertificateForSubject(
|
|
176
|
-
certifierWallet:
|
|
178
|
+
certifierWallet: ProtoWallet,
|
|
177
179
|
subject: WalletCounterparty,
|
|
178
180
|
fields: Record<CertificateFieldNameUnder50Bytes, string>,
|
|
179
181
|
certificateType: string,
|
|
@@ -224,7 +226,7 @@ export class MasterCertificate extends Certificate {
|
|
|
224
226
|
* - If the certificate is self-signed, the counterparty should be set to 'self'.
|
|
225
227
|
* - Otherwise, the counterparty should always be the other party involved in the certificate issuance process (the subject or certifier).
|
|
226
228
|
*
|
|
227
|
-
* @param {
|
|
229
|
+
* @param {ProtoWallet} subjectOrCertifierWallet - The wallet of the subject or certifier, used to decrypt the master keyring and field values.
|
|
228
230
|
* @param {Record<CertificateFieldNameUnder50Bytes, Base64String>} masterKeyring - A record containing encrypted keys for each field.
|
|
229
231
|
* @param {Record<CertificateFieldNameUnder50Bytes, Base64String>} fields - A record of encrypted field names and their values.
|
|
230
232
|
* @param {WalletCounterparty} counterparty - The counterparty responsible for creating or signing the certificate. For self-signed certificates, use 'self'.
|
|
@@ -233,7 +235,7 @@ export class MasterCertificate extends Certificate {
|
|
|
233
235
|
* @throws {Error} Throws an error if the `masterKeyring` is invalid or if decryption fails for any field.
|
|
234
236
|
*/
|
|
235
237
|
static async decryptFields(
|
|
236
|
-
subjectOrCertifierWallet:
|
|
238
|
+
subjectOrCertifierWallet: ProtoWallet,
|
|
237
239
|
masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>,
|
|
238
240
|
fields: Record<CertificateFieldNameUnder50Bytes, Base64String>,
|
|
239
241
|
counterparty: WalletCounterparty
|
|
@@ -254,11 +256,12 @@ export class MasterCertificate extends Certificate {
|
|
|
254
256
|
}
|
|
255
257
|
|
|
256
258
|
static async decryptField(
|
|
257
|
-
subjectOrCertifierWallet:
|
|
259
|
+
subjectOrCertifierWallet: ProtoWallet,
|
|
258
260
|
masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>,
|
|
259
261
|
fieldName: Base64String,
|
|
260
262
|
fieldValue: Base64String,
|
|
261
|
-
counterparty: WalletCounterparty
|
|
263
|
+
counterparty: WalletCounterparty,
|
|
264
|
+
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
262
265
|
): Promise<{ fieldRevelationKey: number[], decryptedFieldValue: string }> {
|
|
263
266
|
if (!masterKeyring || Object.keys(masterKeyring).length === 0) {
|
|
264
267
|
throw new Error('A MasterCertificate must have a valid masterKeyring!')
|
|
@@ -268,7 +271,7 @@ export class MasterCertificate extends Certificate {
|
|
|
268
271
|
ciphertext: Utils.toArray(masterKeyring[fieldName], 'base64'),
|
|
269
272
|
...Certificate.getCertificateFieldEncryptionDetails(fieldName), // Only fieldName used on MasterCertificate
|
|
270
273
|
counterparty
|
|
271
|
-
})
|
|
274
|
+
}, originator)
|
|
272
275
|
|
|
273
276
|
const decryptedFieldValue = new SymmetricKey(fieldRevelationKey).decrypt(Utils.toArray(fieldValue, 'base64'))
|
|
274
277
|
return {
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
HexString,
|
|
7
7
|
OutpointString,
|
|
8
8
|
PubKeyHex,
|
|
9
|
-
|
|
9
|
+
ProtoWallet
|
|
10
10
|
} from '../../../mod.js'
|
|
11
11
|
import Certificate from './Certificate.js'
|
|
12
12
|
|
|
@@ -44,11 +44,11 @@ export class VerifiableCertificate extends Certificate {
|
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* Decrypts selectively revealed certificate fields using the provided keyring and verifier wallet
|
|
47
|
-
* @param {
|
|
47
|
+
* @param {ProtoWallet} verifierWallet - The wallet instance of the certificate's verifier, used to decrypt field keys.
|
|
48
48
|
* @returns {Promise<Record<CertificateFieldNameUnder50Bytes, string>>} - A promise that resolves to an object where each key is a field name and each value is the decrypted field value as a string.
|
|
49
49
|
* @throws {Error} Throws an error if any of the decryption operations fail, with a message indicating the failure context.
|
|
50
50
|
*/
|
|
51
|
-
async decryptFields(verifierWallet:
|
|
51
|
+
async decryptFields(verifierWallet: ProtoWallet): Promise<Record<CertificateFieldNameUnder50Bytes, string>> {
|
|
52
52
|
if (!this.keyring || Object.keys(this.keyring).length === 0) {
|
|
53
53
|
throw new Error('A keyring is required to decrypt certificate fields for the verifier.')
|
|
54
54
|
}
|
|
@@ -3,6 +3,7 @@ import { PrivateKey, SymmetricKey, Utils } from '../../../../dist/cjs/src/primit
|
|
|
3
3
|
import { CompletedProtoWallet } from '../../../../dist/cjs/src/auth/certificates/__tests/CompletedProtoWallet.js'
|
|
4
4
|
import { Certificate } from '../../../../dist/cjs/src/auth/certificates/index.js'
|
|
5
5
|
import { MasterCertificate } from '../../../../dist/cjs/src/auth/certificates/MasterCertificate.js'
|
|
6
|
+
import { ProtoWallet } from '../../../../dist/cjs/src/wallet/index.js'
|
|
6
7
|
|
|
7
8
|
describe('VerifiableCertificate', () => {
|
|
8
9
|
const subjectPrivateKey = PrivateKey.fromRandom()
|
|
@@ -108,5 +109,33 @@ describe('VerifiableCertificate', () => {
|
|
|
108
109
|
/Failed to decrypt selectively revealed certificate fields using keyring/
|
|
109
110
|
)
|
|
110
111
|
})
|
|
112
|
+
|
|
113
|
+
it('should be able to decrypt fields using the anyone wallet', async () => {
|
|
114
|
+
const { certificateFields, masterKeyring } = await MasterCertificate.createCertificateFields(
|
|
115
|
+
subjectWallet,
|
|
116
|
+
certifierIdentityKey,
|
|
117
|
+
plaintextFields
|
|
118
|
+
)
|
|
119
|
+
const keyringForVerifier = await MasterCertificate.createKeyringForVerifier(
|
|
120
|
+
subjectWallet,
|
|
121
|
+
certifierIdentityKey,
|
|
122
|
+
'anyone',
|
|
123
|
+
certificateFields,
|
|
124
|
+
Object.keys(certificateFields),
|
|
125
|
+
masterKeyring,
|
|
126
|
+
sampleSerialNumber
|
|
127
|
+
)
|
|
128
|
+
verifiableCert = new VerifiableCertificate(
|
|
129
|
+
sampleType,
|
|
130
|
+
sampleSerialNumber,
|
|
131
|
+
subjectIdentityKey,
|
|
132
|
+
'anyone',
|
|
133
|
+
sampleRevocationOutpoint,
|
|
134
|
+
certificateFields,
|
|
135
|
+
keyringForVerifier
|
|
136
|
+
)
|
|
137
|
+
const decrypted = await verifiableCert.decryptFields(new ProtoWallet('anyone'))
|
|
138
|
+
expect(decrypted).toEqual(plaintextFields)
|
|
139
|
+
})
|
|
111
140
|
})
|
|
112
141
|
})
|
|
@@ -33,9 +33,9 @@ import {
|
|
|
33
33
|
* enable the management of identity certificates, or store any data. It is also not concerned with privileged keys.
|
|
34
34
|
*/
|
|
35
35
|
export class ProtoWallet {
|
|
36
|
-
keyDeriver
|
|
36
|
+
keyDeriver?: KeyDeriverApi
|
|
37
37
|
|
|
38
|
-
constructor (rootKeyOrKeyDeriver
|
|
38
|
+
constructor (rootKeyOrKeyDeriver?: PrivateKey | 'anyone' | KeyDeriverApi) {
|
|
39
39
|
if (typeof (rootKeyOrKeyDeriver as KeyDeriver).identityKey !== 'string') {
|
|
40
40
|
rootKeyOrKeyDeriver = new KeyDeriver(rootKeyOrKeyDeriver as PrivateKey | 'anyone')
|
|
41
41
|
}
|
|
@@ -43,7 +43,8 @@ export class ProtoWallet {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
async getPublicKey (
|
|
46
|
-
args: GetPublicKeyArgs
|
|
46
|
+
args: GetPublicKeyArgs,
|
|
47
|
+
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
47
48
|
): Promise<{ publicKey: PubKeyHex }> {
|
|
48
49
|
if (args.identityKey) {
|
|
49
50
|
return { publicKey: this.keyDeriver.rootKey.toPublicKey().toString() }
|
|
@@ -65,7 +66,8 @@ export class ProtoWallet {
|
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
async revealCounterpartyKeyLinkage (
|
|
68
|
-
args: RevealCounterpartyKeyLinkageArgs
|
|
69
|
+
args: RevealCounterpartyKeyLinkageArgs,
|
|
70
|
+
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
69
71
|
): Promise<RevealCounterpartyKeyLinkageResult> {
|
|
70
72
|
const { publicKey: identityKey } = await this.getPublicKey({ identityKey: true })
|
|
71
73
|
const linkage = this.keyDeriver.revealCounterpartySecret(args.counterparty)
|
|
@@ -99,7 +101,8 @@ export class ProtoWallet {
|
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
async revealSpecificKeyLinkage (
|
|
102
|
-
args: RevealSpecificKeyLinkageArgs
|
|
104
|
+
args: RevealSpecificKeyLinkageArgs,
|
|
105
|
+
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
103
106
|
): Promise<RevealSpecificKeyLinkageResult> {
|
|
104
107
|
const { publicKey: identityKey } = await this.getPublicKey({ identityKey: true })
|
|
105
108
|
const linkage = this.keyDeriver.revealSpecificSecret(
|
|
@@ -132,7 +135,8 @@ export class ProtoWallet {
|
|
|
132
135
|
}
|
|
133
136
|
|
|
134
137
|
async encrypt (
|
|
135
|
-
args: WalletEncryptArgs
|
|
138
|
+
args: WalletEncryptArgs,
|
|
139
|
+
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
136
140
|
): Promise<WalletEncryptResult> {
|
|
137
141
|
const key = this.keyDeriver.deriveSymmetricKey(
|
|
138
142
|
args.protocolID,
|
|
@@ -143,7 +147,8 @@ export class ProtoWallet {
|
|
|
143
147
|
}
|
|
144
148
|
|
|
145
149
|
async decrypt (
|
|
146
|
-
args: WalletDecryptArgs
|
|
150
|
+
args: WalletDecryptArgs,
|
|
151
|
+
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
147
152
|
): Promise<WalletDecryptResult> {
|
|
148
153
|
const key = this.keyDeriver.deriveSymmetricKey(
|
|
149
154
|
args.protocolID,
|
|
@@ -154,7 +159,8 @@ export class ProtoWallet {
|
|
|
154
159
|
}
|
|
155
160
|
|
|
156
161
|
async createHmac (
|
|
157
|
-
args: CreateHmacArgs
|
|
162
|
+
args: CreateHmacArgs,
|
|
163
|
+
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
158
164
|
): Promise<CreateHmacResult> {
|
|
159
165
|
const key = this.keyDeriver.deriveSymmetricKey(
|
|
160
166
|
args.protocolID,
|
|
@@ -165,7 +171,8 @@ export class ProtoWallet {
|
|
|
165
171
|
}
|
|
166
172
|
|
|
167
173
|
async verifyHmac (
|
|
168
|
-
args: VerifyHmacArgs
|
|
174
|
+
args: VerifyHmacArgs,
|
|
175
|
+
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
169
176
|
): Promise<VerifyHmacResult> {
|
|
170
177
|
const key = this.keyDeriver.deriveSymmetricKey(
|
|
171
178
|
args.protocolID,
|
|
@@ -182,7 +189,8 @@ export class ProtoWallet {
|
|
|
182
189
|
}
|
|
183
190
|
|
|
184
191
|
async createSignature (
|
|
185
|
-
args: CreateSignatureArgs
|
|
192
|
+
args: CreateSignatureArgs,
|
|
193
|
+
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
186
194
|
): Promise<CreateSignatureResult> {
|
|
187
195
|
if (!args.hashToDirectlySign && !args.data) {
|
|
188
196
|
throw new Error('args.data or args.hashToDirectlySign must be valid')
|
|
@@ -197,7 +205,8 @@ export class ProtoWallet {
|
|
|
197
205
|
}
|
|
198
206
|
|
|
199
207
|
async verifySignature (
|
|
200
|
-
args: VerifySignatureArgs
|
|
208
|
+
args: VerifySignatureArgs,
|
|
209
|
+
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
201
210
|
): Promise<VerifySignatureResult> {
|
|
202
211
|
if (!args.hashToDirectlyVerify && !args.data) {
|
|
203
212
|
throw new Error('args.data or args.hashToDirectlyVerify must be valid')
|