@bsv/sdk 1.3.31 → 1.3.33
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 +11 -4
- package/dist/cjs/src/auth/certificates/Certificate.js.map +1 -1
- package/dist/cjs/src/auth/certificates/MasterCertificate.js +25 -15
- package/dist/cjs/src/auth/certificates/MasterCertificate.js.map +1 -1
- package/dist/cjs/src/auth/certificates/VerifiableCertificate.js +6 -2
- package/dist/cjs/src/auth/certificates/VerifiableCertificate.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/auth/certificates/Certificate.js +11 -4
- package/dist/esm/src/auth/certificates/Certificate.js.map +1 -1
- package/dist/esm/src/auth/certificates/MasterCertificate.js +25 -15
- package/dist/esm/src/auth/certificates/MasterCertificate.js.map +1 -1
- package/dist/esm/src/auth/certificates/VerifiableCertificate.js +6 -2
- package/dist/esm/src/auth/certificates/VerifiableCertificate.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/auth/certificates/Certificate.d.ts +10 -3
- package/dist/types/src/auth/certificates/Certificate.d.ts.map +1 -1
- package/dist/types/src/auth/certificates/MasterCertificate.d.ts +10 -4
- package/dist/types/src/auth/certificates/MasterCertificate.d.ts.map +1 -1
- package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts +3 -1
- package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/docs/auth.md +36 -13
- package/package.json +1 -1
- package/src/auth/certificates/Certificate.ts +11 -4
- package/src/auth/certificates/MasterCertificate.ts +37 -13
- package/src/auth/certificates/VerifiableCertificate.ts +8 -2
package/docs/auth.md
CHANGED
|
@@ -334,6 +334,12 @@ Argument Details
|
|
|
334
334
|
|
|
335
335
|
Helper function which retrieves the protocol ID and key ID for certificate field encryption.
|
|
336
336
|
|
|
337
|
+
For master certificate creation, no serial number is provided because entropy is required
|
|
338
|
+
from both the client and the certifier. In this case, the `keyID` is simply the `fieldName`.
|
|
339
|
+
|
|
340
|
+
For VerifiableCertificates verifier keyring creation, both the serial number and field name are available,
|
|
341
|
+
so the `keyID` is formed by concatenating the `serialNumber` and `fieldName`.
|
|
342
|
+
|
|
337
343
|
```ts
|
|
338
344
|
static getCertificateFieldEncryptionDetails(fieldName: string, serialNumber?: string): {
|
|
339
345
|
protocolID: WalletProtocol;
|
|
@@ -344,16 +350,17 @@ See also: [WalletProtocol](./wallet.md#type-walletprotocol)
|
|
|
344
350
|
|
|
345
351
|
Returns
|
|
346
352
|
|
|
347
|
-
An object containing
|
|
353
|
+
An object containing:
|
|
348
354
|
- `protocolID` (WalletProtocol): The protocol ID for certificate field encryption.
|
|
349
|
-
- `keyID` (string): A unique key identifier
|
|
355
|
+
- `keyID` (string): A unique key identifier. It is the `fieldName` if `serialNumber` is undefined,
|
|
356
|
+
otherwise it is a combination of `serialNumber` and `fieldName`.
|
|
350
357
|
|
|
351
358
|
Argument Details
|
|
352
359
|
|
|
353
|
-
+ **serialNumber**
|
|
354
|
-
+ The serial number of the certificate.
|
|
355
360
|
+ **fieldName**
|
|
356
361
|
+ The name of the field within the certificate to be encrypted.
|
|
362
|
+
+ **serialNumber**
|
|
363
|
+
+ (Optional) The serial number of the certificate.
|
|
357
364
|
|
|
358
365
|
#### Method sign
|
|
359
366
|
|
|
@@ -456,14 +463,14 @@ export class MasterCertificate extends Certificate {
|
|
|
456
463
|
declare signature?: HexString;
|
|
457
464
|
masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>;
|
|
458
465
|
constructor(type: Base64String, serialNumber: Base64String, subject: PubKeyHex, certifier: PubKeyHex, revocationOutpoint: OutpointString, fields: Record<CertificateFieldNameUnder50Bytes, Base64String>, masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>, signature?: HexString)
|
|
459
|
-
static async createCertificateFields(creatorWallet: ProtoWallet, certifierOrSubject: WalletCounterparty, fields: Record<CertificateFieldNameUnder50Bytes, string
|
|
460
|
-
static async createKeyringForVerifier(subjectWallet: ProtoWallet, certifier: WalletCounterparty, verifier: WalletCounterparty, fields: Record<CertificateFieldNameUnder50Bytes, Base64String>, fieldsToReveal: string[], masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>, serialNumber: Base64String): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
|
|
466
|
+
static async createCertificateFields(creatorWallet: ProtoWallet, certifierOrSubject: WalletCounterparty, fields: Record<CertificateFieldNameUnder50Bytes, string>, privileged?: boolean, privilegedReason?: string): Promise<CreateCertificateFieldsResult>
|
|
467
|
+
static async createKeyringForVerifier(subjectWallet: ProtoWallet, certifier: WalletCounterparty, verifier: WalletCounterparty, fields: Record<CertificateFieldNameUnder50Bytes, Base64String>, fieldsToReveal: string[], masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>, serialNumber: Base64String, privileged?: boolean, privilegedReason?: string): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
|
|
461
468
|
static async issueCertificateForSubject(certifierWallet: ProtoWallet, subject: WalletCounterparty, fields: Record<CertificateFieldNameUnder50Bytes, string>, certificateType: string, getRevocationOutpoint = async (_serial: string): Promise<string> => {
|
|
462
469
|
void _serial;
|
|
463
470
|
return "Certificate revocation not tracked.";
|
|
464
471
|
}, serialNumber?: string): Promise<MasterCertificate>
|
|
465
|
-
static async decryptFields(subjectOrCertifierWallet: ProtoWallet, masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>, fields: Record<CertificateFieldNameUnder50Bytes, Base64String>, counterparty: WalletCounterparty): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
|
|
466
|
-
static async decryptField(subjectOrCertifierWallet: ProtoWallet, masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>, fieldName: Base64String, fieldValue: Base64String, counterparty: WalletCounterparty): Promise<{
|
|
472
|
+
static async decryptFields(subjectOrCertifierWallet: ProtoWallet, masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>, fields: Record<CertificateFieldNameUnder50Bytes, Base64String>, counterparty: WalletCounterparty, privileged?: boolean, privilegedReason?: string): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
|
|
473
|
+
static async decryptField(subjectOrCertifierWallet: ProtoWallet, masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>, fieldName: Base64String, fieldValue: Base64String, counterparty: WalletCounterparty, privileged?: boolean, privilegedReason?: string): Promise<{
|
|
467
474
|
fieldRevelationKey: number[];
|
|
468
475
|
decryptedFieldValue: string;
|
|
469
476
|
}>
|
|
@@ -479,7 +486,7 @@ This method returns a master keyring tied to a specific certifier or subject who
|
|
|
479
486
|
and sign off on the fields, along with the encrypted certificate fields.
|
|
480
487
|
|
|
481
488
|
```ts
|
|
482
|
-
static async createCertificateFields(creatorWallet: ProtoWallet, certifierOrSubject: WalletCounterparty, fields: Record<CertificateFieldNameUnder50Bytes, string
|
|
489
|
+
static async createCertificateFields(creatorWallet: ProtoWallet, certifierOrSubject: WalletCounterparty, fields: Record<CertificateFieldNameUnder50Bytes, string>, privileged?: boolean, privilegedReason?: string): Promise<CreateCertificateFieldsResult>
|
|
483
490
|
```
|
|
484
491
|
See also: [CertificateFieldNameUnder50Bytes](./wallet.md#type-certificatefieldnameunder50bytes), [ProtoWallet](./wallet.md#class-protowallet), [WalletCounterparty](./wallet.md#type-walletcounterparty)
|
|
485
492
|
|
|
@@ -499,6 +506,10 @@ Argument Details
|
|
|
499
506
|
+ The certifier or subject who will validate the certificate fields.
|
|
500
507
|
+ **fields**
|
|
501
508
|
+ A record of certificate field names (under 50 bytes) mapped to their values.
|
|
509
|
+
+ **privileged**
|
|
510
|
+
+ Whether this is a privileged request.
|
|
511
|
+
+ **privilegedReason**
|
|
512
|
+
+ Reason provided for privileged access, required if this is a privileged operation. *
|
|
502
513
|
|
|
503
514
|
#### Method createKeyringForVerifier
|
|
504
515
|
|
|
@@ -508,7 +519,7 @@ for the verifier's identity key. The result is a keyring containing the keys nec
|
|
|
508
519
|
for the verifier to access the designated fields.
|
|
509
520
|
|
|
510
521
|
```ts
|
|
511
|
-
static async createKeyringForVerifier(subjectWallet: ProtoWallet, certifier: WalletCounterparty, verifier: WalletCounterparty, fields: Record<CertificateFieldNameUnder50Bytes, Base64String>, fieldsToReveal: string[], masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>, serialNumber: Base64String): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
|
|
522
|
+
static async createKeyringForVerifier(subjectWallet: ProtoWallet, certifier: WalletCounterparty, verifier: WalletCounterparty, fields: Record<CertificateFieldNameUnder50Bytes, Base64String>, fieldsToReveal: string[], masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>, serialNumber: Base64String, privileged?: boolean, privilegedReason?: string): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
|
|
512
523
|
```
|
|
513
524
|
See also: [Base64String](./wallet.md#type-base64string), [CertificateFieldNameUnder50Bytes](./wallet.md#type-certificatefieldnameunder50bytes), [ProtoWallet](./wallet.md#class-protowallet), [WalletCounterparty](./wallet.md#type-walletcounterparty)
|
|
514
525
|
|
|
@@ -526,6 +537,10 @@ Argument Details
|
|
|
526
537
|
+ An array of field names to be revealed to the verifier. Must be a subset of the certificate's fields.
|
|
527
538
|
+ **originator**
|
|
528
539
|
+ Optional originator identifier, used if additional context is needed for decryption and encryption operations.
|
|
540
|
+
+ **privileged**
|
|
541
|
+
+ Whether this is a privileged request.
|
|
542
|
+
+ **privilegedReason**
|
|
543
|
+
+ Reason provided for privileged access, required if this is a privileged operation. *
|
|
529
544
|
|
|
530
545
|
Throws
|
|
531
546
|
|
|
@@ -545,7 +560,7 @@ The counterparty used for decryption depends on how the certificate fields were
|
|
|
545
560
|
- Otherwise, the counterparty should always be the other party involved in the certificate issuance process (the subject or certifier).
|
|
546
561
|
|
|
547
562
|
```ts
|
|
548
|
-
static async decryptFields(subjectOrCertifierWallet: ProtoWallet, masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>, fields: Record<CertificateFieldNameUnder50Bytes, Base64String>, counterparty: WalletCounterparty): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
|
|
563
|
+
static async decryptFields(subjectOrCertifierWallet: ProtoWallet, masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>, fields: Record<CertificateFieldNameUnder50Bytes, Base64String>, counterparty: WalletCounterparty, privileged?: boolean, privilegedReason?: string): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
|
|
549
564
|
```
|
|
550
565
|
See also: [Base64String](./wallet.md#type-base64string), [CertificateFieldNameUnder50Bytes](./wallet.md#type-certificatefieldnameunder50bytes), [ProtoWallet](./wallet.md#class-protowallet), [WalletCounterparty](./wallet.md#type-walletcounterparty)
|
|
551
566
|
|
|
@@ -563,6 +578,10 @@ Argument Details
|
|
|
563
578
|
+ A record of encrypted field names and their values.
|
|
564
579
|
+ **counterparty**
|
|
565
580
|
+ The counterparty responsible for creating or signing the certificate. For self-signed certificates, use 'self'.
|
|
581
|
+
+ **privileged**
|
|
582
|
+
+ Whether this is a privileged request.
|
|
583
|
+
+ **privilegedReason**
|
|
584
|
+
+ Reason provided for privileged access, required if this is a privileged operation.
|
|
566
585
|
|
|
567
586
|
Throws
|
|
568
587
|
|
|
@@ -1087,7 +1106,7 @@ export class VerifiableCertificate extends Certificate {
|
|
|
1087
1106
|
keyring: Record<CertificateFieldNameUnder50Bytes, string>;
|
|
1088
1107
|
decryptedFields?: Record<CertificateFieldNameUnder50Bytes, Base64String>;
|
|
1089
1108
|
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>)
|
|
1090
|
-
async decryptFields(verifierWallet: ProtoWallet): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
|
|
1109
|
+
async decryptFields(verifierWallet: ProtoWallet, privileged?: boolean, privilegedReason?: string): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
|
|
1091
1110
|
}
|
|
1092
1111
|
```
|
|
1093
1112
|
|
|
@@ -1098,7 +1117,7 @@ See also: [Base64String](./wallet.md#type-base64string), [Certificate](./auth.md
|
|
|
1098
1117
|
Decrypts selectively revealed certificate fields using the provided keyring and verifier wallet
|
|
1099
1118
|
|
|
1100
1119
|
```ts
|
|
1101
|
-
async decryptFields(verifierWallet: ProtoWallet): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
|
|
1120
|
+
async decryptFields(verifierWallet: ProtoWallet, privileged?: boolean, privilegedReason?: string): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
|
|
1102
1121
|
```
|
|
1103
1122
|
See also: [CertificateFieldNameUnder50Bytes](./wallet.md#type-certificatefieldnameunder50bytes), [ProtoWallet](./wallet.md#class-protowallet)
|
|
1104
1123
|
|
|
@@ -1110,6 +1129,10 @@ Argument Details
|
|
|
1110
1129
|
|
|
1111
1130
|
+ **verifierWallet**
|
|
1112
1131
|
+ The wallet instance of the certificate's verifier, used to decrypt field keys.
|
|
1132
|
+
+ **privileged**
|
|
1133
|
+
+ Whether this is a privileged request.
|
|
1134
|
+
+ **privilegedReason**
|
|
1135
|
+
+ Reason provided for privileged access, required if this is a privileged operation.
|
|
1113
1136
|
|
|
1114
1137
|
Throws
|
|
1115
1138
|
|
package/package.json
CHANGED
|
@@ -258,11 +258,18 @@ export default class Certificate {
|
|
|
258
258
|
/**
|
|
259
259
|
* Helper function which retrieves the protocol ID and key ID for certificate field encryption.
|
|
260
260
|
*
|
|
261
|
-
*
|
|
261
|
+
* For master certificate creation, no serial number is provided because entropy is required
|
|
262
|
+
* from both the client and the certifier. In this case, the `keyID` is simply the `fieldName`.
|
|
263
|
+
*
|
|
264
|
+
* For VerifiableCertificates verifier keyring creation, both the serial number and field name are available,
|
|
265
|
+
* so the `keyID` is formed by concatenating the `serialNumber` and `fieldName`.
|
|
266
|
+
*
|
|
262
267
|
* @param fieldName - The name of the field within the certificate to be encrypted.
|
|
263
|
-
* @
|
|
268
|
+
* @param serialNumber - (Optional) The serial number of the certificate.
|
|
269
|
+
* @returns An object containing:
|
|
264
270
|
* - `protocolID` (WalletProtocol): The protocol ID for certificate field encryption.
|
|
265
|
-
* - `keyID` (string): A unique key identifier
|
|
271
|
+
* - `keyID` (string): A unique key identifier. It is the `fieldName` if `serialNumber` is undefined,
|
|
272
|
+
* otherwise it is a combination of `serialNumber` and `fieldName`.
|
|
266
273
|
*/
|
|
267
274
|
static getCertificateFieldEncryptionDetails(
|
|
268
275
|
fieldName: string,
|
|
@@ -270,7 +277,7 @@ export default class Certificate {
|
|
|
270
277
|
): { protocolID: WalletProtocol, keyID: string } {
|
|
271
278
|
return {
|
|
272
279
|
protocolID: [2, 'certificate field encryption'],
|
|
273
|
-
keyID: `${serialNumber
|
|
280
|
+
keyID: serialNumber ? `${serialNumber} ${fieldName}` : fieldName
|
|
274
281
|
}
|
|
275
282
|
}
|
|
276
283
|
}
|
|
@@ -76,6 +76,8 @@ export class MasterCertificate extends Certificate {
|
|
|
76
76
|
* @param {ProtoWallet} creatorWallet - The wallet of the creator responsible for encrypting the fields.
|
|
77
77
|
* @param {WalletCounterparty} certifierOrSubject - The certifier or subject who will validate the certificate fields.
|
|
78
78
|
* @param {Record<CertificateFieldNameUnder50Bytes, string>} fields - A record of certificate field names (under 50 bytes) mapped to their values.
|
|
79
|
+
* @param {BooleanDefaultFalse} [privileged] - Whether this is a privileged request.
|
|
80
|
+
* @param {DescriptionString5to50Bytes} [privilegedReason] - Reason provided for privileged access, required if this is a privileged operation. *
|
|
79
81
|
* @returns {Promise<CreateCertificateFieldsResult>} A promise resolving to an object containing:
|
|
80
82
|
* - `certificateFields` {Record<CertificateFieldNameUnder50Bytes, Base64String>}:
|
|
81
83
|
* The encrypted certificate fields.
|
|
@@ -85,7 +87,9 @@ export class MasterCertificate extends Certificate {
|
|
|
85
87
|
static async createCertificateFields(
|
|
86
88
|
creatorWallet: ProtoWallet,
|
|
87
89
|
certifierOrSubject: WalletCounterparty,
|
|
88
|
-
fields: Record<CertificateFieldNameUnder50Bytes, string
|
|
90
|
+
fields: Record<CertificateFieldNameUnder50Bytes, string>,
|
|
91
|
+
privileged?: boolean,
|
|
92
|
+
privilegedReason?: string
|
|
89
93
|
): Promise<CreateCertificateFieldsResult> {
|
|
90
94
|
const certificateFields: Record<
|
|
91
95
|
CertificateFieldNameUnder50Bytes,
|
|
@@ -109,7 +113,9 @@ export class MasterCertificate extends Certificate {
|
|
|
109
113
|
{
|
|
110
114
|
plaintext: fieldSymmetricKey.toArray(),
|
|
111
115
|
...Certificate.getCertificateFieldEncryptionDetails(fieldName), // Only fieldName used on MasterCertificate
|
|
112
|
-
counterparty: certifierOrSubject
|
|
116
|
+
counterparty: certifierOrSubject,
|
|
117
|
+
privileged,
|
|
118
|
+
privilegedReason
|
|
113
119
|
}
|
|
114
120
|
)
|
|
115
121
|
masterKeyring[fieldName] = Utils.toBase64(encryptedFieldRevelationKey)
|
|
@@ -132,6 +138,8 @@ export class MasterCertificate extends Certificate {
|
|
|
132
138
|
* @param {string[]} fieldsToReveal - An array of field names to be revealed to the verifier. Must be a subset of the certificate's fields.
|
|
133
139
|
* @param {string} [originator] - Optional originator identifier, used if additional context is needed for decryption and encryption operations.
|
|
134
140
|
* @returns {Promise<Record<CertificateFieldNameUnder50Bytes, string>>} - A keyring mapping field names to encrypted field revelation keys, allowing the verifier to decrypt specified fields.
|
|
141
|
+
* @param {BooleanDefaultFalse} [privileged] - Whether this is a privileged request.
|
|
142
|
+
* @param {DescriptionString5to50Bytes} [privilegedReason] - Reason provided for privileged access, required if this is a privileged operation. *
|
|
135
143
|
* @throws {Error} Throws an error if:
|
|
136
144
|
* - fieldsToReveal is not an array of strings.
|
|
137
145
|
* - A field in `fieldsToReveal` does not exist in the certificate.
|
|
@@ -144,7 +152,9 @@ export class MasterCertificate extends Certificate {
|
|
|
144
152
|
fields: Record<CertificateFieldNameUnder50Bytes, Base64String>,
|
|
145
153
|
fieldsToReveal: string[],
|
|
146
154
|
masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>,
|
|
147
|
-
serialNumber: Base64String
|
|
155
|
+
serialNumber: Base64String,
|
|
156
|
+
privileged?: boolean,
|
|
157
|
+
privilegedReason?: string
|
|
148
158
|
): Promise<Record<CertificateFieldNameUnder50Bytes, string>> {
|
|
149
159
|
if (!Array.isArray(fieldsToReveal)) {
|
|
150
160
|
throw new Error('fieldsToReveal must be an array of strings')
|
|
@@ -165,7 +175,9 @@ export class MasterCertificate extends Certificate {
|
|
|
165
175
|
masterKeyring,
|
|
166
176
|
fieldName,
|
|
167
177
|
fields[fieldName],
|
|
168
|
-
certifier
|
|
178
|
+
certifier,
|
|
179
|
+
privileged,
|
|
180
|
+
privilegedReason
|
|
169
181
|
)
|
|
170
182
|
).fieldRevelationKey
|
|
171
183
|
|
|
@@ -178,7 +190,9 @@ export class MasterCertificate extends Certificate {
|
|
|
178
190
|
fieldName,
|
|
179
191
|
serialNumber
|
|
180
192
|
),
|
|
181
|
-
counterparty: verifier
|
|
193
|
+
counterparty: verifier,
|
|
194
|
+
privileged,
|
|
195
|
+
privilegedReason
|
|
182
196
|
}
|
|
183
197
|
)
|
|
184
198
|
|
|
@@ -220,22 +234,22 @@ export class MasterCertificate extends Certificate {
|
|
|
220
234
|
void _serial // Explicitly acknowledge unused parameter
|
|
221
235
|
return 'Certificate revocation not tracked.'
|
|
222
236
|
},
|
|
223
|
-
serialNumber?: string
|
|
237
|
+
serialNumber?: string
|
|
224
238
|
): Promise<MasterCertificate> {
|
|
225
239
|
// 1. Generate a random serialNumber if not provided
|
|
226
|
-
const finalSerialNumber = serialNumber ?? Utils.toBase64(Random(32))
|
|
240
|
+
const finalSerialNumber = serialNumber ?? Utils.toBase64(Random(32))
|
|
227
241
|
|
|
228
242
|
// 2. Create encrypted certificate fields and associated master keyring
|
|
229
243
|
const { certificateFields, masterKeyring } =
|
|
230
244
|
await this.createCertificateFields(certifierWallet, subject, fields)
|
|
231
245
|
|
|
232
246
|
// 3. Obtain a revocation outpoint
|
|
233
|
-
const revocationOutpoint = await getRevocationOutpoint(finalSerialNumber)
|
|
247
|
+
const revocationOutpoint = await getRevocationOutpoint(finalSerialNumber)
|
|
234
248
|
|
|
235
249
|
// 4. Create new MasterCertificate instance
|
|
236
250
|
const certificate = new MasterCertificate(
|
|
237
251
|
certificateType,
|
|
238
|
-
finalSerialNumber,
|
|
252
|
+
finalSerialNumber,
|
|
239
253
|
subject,
|
|
240
254
|
(await certifierWallet.getPublicKey({ identityKey: true })).publicKey,
|
|
241
255
|
revocationOutpoint,
|
|
@@ -261,6 +275,8 @@ export class MasterCertificate extends Certificate {
|
|
|
261
275
|
* @param {Record<CertificateFieldNameUnder50Bytes, Base64String>} masterKeyring - A record containing encrypted keys for each field.
|
|
262
276
|
* @param {Record<CertificateFieldNameUnder50Bytes, Base64String>} fields - A record of encrypted field names and their values.
|
|
263
277
|
* @param {WalletCounterparty} counterparty - The counterparty responsible for creating or signing the certificate. For self-signed certificates, use 'self'.
|
|
278
|
+
* @param {BooleanDefaultFalse} [privileged] - Whether this is a privileged request.
|
|
279
|
+
* @param {DescriptionString5to50Bytes} [privilegedReason] - Reason provided for privileged access, required if this is a privileged operation.
|
|
264
280
|
* @returns {Promise<Record<CertificateFieldNameUnder50Bytes, string>>} A promise resolving to a record of field names and their decrypted values in plaintext.
|
|
265
281
|
*
|
|
266
282
|
* @throws {Error} Throws an error if the `masterKeyring` is invalid or if decryption fails for any field.
|
|
@@ -269,7 +285,9 @@ export class MasterCertificate extends Certificate {
|
|
|
269
285
|
subjectOrCertifierWallet: ProtoWallet,
|
|
270
286
|
masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>,
|
|
271
287
|
fields: Record<CertificateFieldNameUnder50Bytes, Base64String>,
|
|
272
|
-
counterparty: WalletCounterparty
|
|
288
|
+
counterparty: WalletCounterparty,
|
|
289
|
+
privileged?: boolean,
|
|
290
|
+
privilegedReason?: string
|
|
273
291
|
): Promise<Record<CertificateFieldNameUnder50Bytes, string>> {
|
|
274
292
|
if (masterKeyring == null || Object.keys(masterKeyring).length === 0) {
|
|
275
293
|
throw new Error('A MasterCertificate must have a valid masterKeyring!')
|
|
@@ -285,7 +303,9 @@ export class MasterCertificate extends Certificate {
|
|
|
285
303
|
masterKeyring,
|
|
286
304
|
fieldName,
|
|
287
305
|
fields[fieldName],
|
|
288
|
-
counterparty
|
|
306
|
+
counterparty,
|
|
307
|
+
privileged,
|
|
308
|
+
privilegedReason
|
|
289
309
|
)
|
|
290
310
|
).decryptedFieldValue
|
|
291
311
|
}
|
|
@@ -300,7 +320,9 @@ export class MasterCertificate extends Certificate {
|
|
|
300
320
|
masterKeyring: Record<CertificateFieldNameUnder50Bytes, Base64String>,
|
|
301
321
|
fieldName: Base64String,
|
|
302
322
|
fieldValue: Base64String,
|
|
303
|
-
counterparty: WalletCounterparty
|
|
323
|
+
counterparty: WalletCounterparty,
|
|
324
|
+
privileged?: boolean,
|
|
325
|
+
privilegedReason?: string
|
|
304
326
|
): Promise<{ fieldRevelationKey: number[], decryptedFieldValue: string }> {
|
|
305
327
|
if (masterKeyring == null || Object.keys(masterKeyring).length === 0) {
|
|
306
328
|
throw new Error('A MasterCertificate must have a valid masterKeyring!')
|
|
@@ -311,7 +333,9 @@ export class MasterCertificate extends Certificate {
|
|
|
311
333
|
{
|
|
312
334
|
ciphertext: Utils.toArray(masterKeyring[fieldName], 'base64'),
|
|
313
335
|
...Certificate.getCertificateFieldEncryptionDetails(fieldName), // Only fieldName used on MasterCertificate
|
|
314
|
-
counterparty
|
|
336
|
+
counterparty,
|
|
337
|
+
privileged,
|
|
338
|
+
privilegedReason
|
|
315
339
|
}
|
|
316
340
|
)
|
|
317
341
|
|
|
@@ -54,10 +54,14 @@ export class VerifiableCertificate extends Certificate {
|
|
|
54
54
|
* Decrypts selectively revealed certificate fields using the provided keyring and verifier wallet
|
|
55
55
|
* @param {ProtoWallet} verifierWallet - The wallet instance of the certificate's verifier, used to decrypt field keys.
|
|
56
56
|
* @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.
|
|
57
|
+
* @param {BooleanDefaultFalse} [privileged] - Whether this is a privileged request.
|
|
58
|
+
* @param {DescriptionString5to50Bytes} [privilegedReason] - Reason provided for privileged access, required if this is a privileged operation.
|
|
57
59
|
* @throws {Error} Throws an error if any of the decryption operations fail, with a message indicating the failure context.
|
|
58
60
|
*/
|
|
59
61
|
async decryptFields(
|
|
60
|
-
verifierWallet: ProtoWallet
|
|
62
|
+
verifierWallet: ProtoWallet,
|
|
63
|
+
privileged?: boolean,
|
|
64
|
+
privilegedReason?: string
|
|
61
65
|
): Promise<Record<CertificateFieldNameUnder50Bytes, string>> {
|
|
62
66
|
if (this.keyring == null || Object.keys(this.keyring).length === 0) { // ✅ Explicitly check null and empty object
|
|
63
67
|
throw new Error(
|
|
@@ -75,7 +79,9 @@ export class VerifiableCertificate extends Certificate {
|
|
|
75
79
|
fieldName,
|
|
76
80
|
this.serialNumber
|
|
77
81
|
),
|
|
78
|
-
counterparty: this.subject
|
|
82
|
+
counterparty: this.subject,
|
|
83
|
+
privileged,
|
|
84
|
+
privilegedReason
|
|
79
85
|
})
|
|
80
86
|
|
|
81
87
|
const fieldValue = new SymmetricKey(fieldRevelationKey).decrypt(
|