@bsv/sdk 1.3.10 → 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 +1 -1
- package/dist/cjs/src/auth/certificates/Certificate.js.map +1 -1
- package/dist/cjs/src/auth/certificates/MasterCertificate.js +95 -65
- package/dist/cjs/src/auth/certificates/MasterCertificate.js.map +1 -1
- package/dist/cjs/src/auth/certificates/VerifiableCertificate.js +3 -3
- package/dist/cjs/src/auth/certificates/VerifiableCertificate.js.map +1 -1
- package/dist/cjs/src/auth/utils/getVerifiableCertificates.js +1 -1
- package/dist/cjs/src/auth/utils/getVerifiableCertificates.js.map +1 -1
- package/dist/cjs/src/auth/utils/validateCertificates.js +1 -1
- package/dist/cjs/src/auth/utils/validateCertificates.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 +2 -2
- package/dist/esm/src/auth/certificates/Certificate.js.map +1 -1
- package/dist/esm/src/auth/certificates/MasterCertificate.js +95 -65
- package/dist/esm/src/auth/certificates/MasterCertificate.js.map +1 -1
- package/dist/esm/src/auth/certificates/VerifiableCertificate.js +3 -3
- package/dist/esm/src/auth/certificates/VerifiableCertificate.js.map +1 -1
- package/dist/esm/src/auth/utils/getVerifiableCertificates.js +1 -1
- package/dist/esm/src/auth/utils/getVerifiableCertificates.js.map +1 -1
- package/dist/esm/src/auth/utils/validateCertificates.js +1 -1
- package/dist/esm/src/auth/utils/validateCertificates.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 +5 -5
- package/dist/types/src/auth/certificates/Certificate.d.ts.map +1 -1
- package/dist/types/src/auth/certificates/MasterCertificate.d.ts +44 -14
- package/dist/types/src/auth/certificates/MasterCertificate.d.ts.map +1 -1
- package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts +4 -4
- 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 +75 -33
- package/docs/wallet.md +12 -12
- package/package.json +1 -1
- package/src/auth/__tests/Peer.test.ts +19 -47
- package/src/auth/certificates/Certificate.ts +4 -5
- package/src/auth/certificates/MasterCertificate.ts +138 -71
- package/src/auth/certificates/VerifiableCertificate.ts +5 -6
- package/src/auth/certificates/__tests/MasterCertificate.test.ts +142 -51
- package/src/auth/certificates/__tests/VerifiableCertificate.test.ts +54 -30
- package/src/auth/utils/getVerifiableCertificates.ts +2 -2
- package/src/auth/utils/validateCertificates.ts +2 -2
- package/src/wallet/ProtoWallet.ts +20 -11
|
@@ -21,38 +21,37 @@ export class MasterCertificate extends Certificate {
|
|
|
21
21
|
this.masterKeyring = masterKeyring;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* Encrypts certificate fields for a subject and generates a master keyring.
|
|
25
|
+
* This method returns a master keyring tied to a specific certifier or subject who will validate
|
|
26
|
+
* and sign off on the fields, along with the encrypted certificate fields.
|
|
25
27
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* @
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
28
|
+
* @param {ProtoWallet} creatorWallet - The wallet of the creator responsible for encrypting the fields.
|
|
29
|
+
* @param {WalletCounterparty} certifierOrSubject - The certifier or subject who will validate the certificate fields.
|
|
30
|
+
* @param {Record<CertificateFieldNameUnder50Bytes, string>} fields - A record of certificate field names (under 50 bytes) mapped to their values.
|
|
31
|
+
* @returns {Promise<CreateCertificateFieldsResult>} A promise resolving to an object containing:
|
|
32
|
+
* - `certificateFields` {Record<CertificateFieldNameUnder50Bytes, Base64String>}:
|
|
33
|
+
* The encrypted certificate fields.
|
|
34
|
+
* - `masterKeyring` {Record<CertificateFieldNameUnder50Bytes, Base64String>}:
|
|
35
|
+
* The master keyring containing encrypted revelation keys for each field.
|
|
33
36
|
*/
|
|
34
|
-
async
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
});
|
|
48
|
-
const fieldValue = new SymmetricKey(fieldRevelationKey).decrypt(Utils.toArray(this.fields[fieldName], 'base64'));
|
|
49
|
-
decryptedFields[fieldName] = Utils.toUTF8(fieldValue);
|
|
50
|
-
}
|
|
51
|
-
return decryptedFields;
|
|
52
|
-
}
|
|
53
|
-
catch (e) {
|
|
54
|
-
throw new Error('Failed to decrypt all master certificate fields.');
|
|
37
|
+
static async createCertificateFields(creatorWallet, certifierOrSubject, fields, originator) {
|
|
38
|
+
const certificateFields = {};
|
|
39
|
+
const masterKeyring = {};
|
|
40
|
+
for (const [fieldName, fieldValue] of Object.entries(fields)) {
|
|
41
|
+
const fieldSymmetricKey = SymmetricKey.fromRandom();
|
|
42
|
+
const encryptedFieldValue = fieldSymmetricKey.encrypt(Utils.toArray(fieldValue, 'utf8'));
|
|
43
|
+
certificateFields[fieldName] = Utils.toBase64(encryptedFieldValue);
|
|
44
|
+
const { ciphertext: encryptedFieldRevelationKey } = await creatorWallet.encrypt({
|
|
45
|
+
plaintext: fieldSymmetricKey.toArray(),
|
|
46
|
+
...Certificate.getCertificateFieldEncryptionDetails(fieldName), // Only fieldName used on MasterCertificate
|
|
47
|
+
counterparty: certifierOrSubject
|
|
48
|
+
}, originator);
|
|
49
|
+
masterKeyring[fieldName] = Utils.toBase64(encryptedFieldRevelationKey);
|
|
55
50
|
}
|
|
51
|
+
return {
|
|
52
|
+
certificateFields,
|
|
53
|
+
masterKeyring
|
|
54
|
+
};
|
|
56
55
|
}
|
|
57
56
|
/**
|
|
58
57
|
* Creates a keyring for a verifier, enabling them to decrypt specific certificate fields.
|
|
@@ -60,7 +59,7 @@ export class MasterCertificate extends Certificate {
|
|
|
60
59
|
* for the verifier's identity key. The result is a keyring containing the keys necessary
|
|
61
60
|
* for the verifier to access the designated fields.
|
|
62
61
|
*
|
|
63
|
-
* @param {
|
|
62
|
+
* @param {ProtoWallet} subjectWallet - The wallet instance of the subject, used to decrypt and re-encrypt field keys.
|
|
64
63
|
* @param {WalletCounterparty} verifier - The verifier who will receive access to the selectively revealed fields. Can be an identity key as hex, 'anyone', or 'self'.
|
|
65
64
|
* @param {string[]} fieldsToReveal - An array of field names to be revealed to the verifier. Must be a subset of the certificate's fields.
|
|
66
65
|
* @param {string} [originator] - Optional originator identifier, used if additional context is needed for decryption and encryption operations.
|
|
@@ -70,34 +69,22 @@ export class MasterCertificate extends Certificate {
|
|
|
70
69
|
* - A field in `fieldsToReveal` does not exist in the certificate.
|
|
71
70
|
* - The decrypted master field key fails to decrypt the corresponding field (indicating an invalid key).
|
|
72
71
|
*/
|
|
73
|
-
async createKeyringForVerifier(subjectWallet, verifier, fieldsToReveal, originator) {
|
|
72
|
+
static async createKeyringForVerifier(subjectWallet, certifier, verifier, fields, fieldsToReveal, masterKeyring, serialNumber, originator) {
|
|
74
73
|
if (!Array.isArray(fieldsToReveal)) {
|
|
75
74
|
throw new Error('fieldsToReveal must be an array of strings');
|
|
76
75
|
}
|
|
77
76
|
const fieldRevelationKeyring = {};
|
|
78
77
|
for (const fieldName of fieldsToReveal) {
|
|
79
78
|
// Make sure that fields to reveal is a subset of the certificate fields
|
|
80
|
-
if (!
|
|
79
|
+
if (!fields[fieldName]) {
|
|
81
80
|
throw new Error(`Fields to reveal must be a subset of the certificate fields. Missing the "${fieldName}" field.`);
|
|
82
81
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const { plaintext: masterFieldKey } = await subjectWallet.decrypt({
|
|
86
|
-
ciphertext: Utils.toArray(encryptedMasterFieldKey, 'base64'),
|
|
87
|
-
...Certificate.getCertificateFieldEncryptionDetails(this.serialNumber, fieldName),
|
|
88
|
-
counterparty: this.certifier
|
|
89
|
-
}, originator);
|
|
90
|
-
// Verify that derived key actually decrypts requested field
|
|
91
|
-
try {
|
|
92
|
-
new SymmetricKey(masterFieldKey).decrypt(Utils.toArray(this.fields[fieldName], 'base64'));
|
|
93
|
-
}
|
|
94
|
-
catch (_) {
|
|
95
|
-
throw new Error(`Decryption of the "${fieldName}" field with its revelation key failed.`);
|
|
96
|
-
}
|
|
82
|
+
// Decrypt the master field key and verify that derived key actually decrypts requested field
|
|
83
|
+
const masterFieldKey = (await this.decryptField(subjectWallet, masterKeyring, fieldName, fields[fieldName], certifier)).fieldRevelationKey;
|
|
97
84
|
// Encrypt derived fieldRevelationKey for verifier
|
|
98
85
|
const { ciphertext: encryptedFieldRevelationKey } = await subjectWallet.encrypt({
|
|
99
86
|
plaintext: masterFieldKey,
|
|
100
|
-
...Certificate.getCertificateFieldEncryptionDetails(
|
|
87
|
+
...Certificate.getCertificateFieldEncryptionDetails(fieldName, serialNumber),
|
|
101
88
|
counterparty: verifier
|
|
102
89
|
}, originator);
|
|
103
90
|
// Add encryptedFieldRevelationKey to fieldRevelationKeyring
|
|
@@ -114,7 +101,7 @@ export class MasterCertificate extends Certificate {
|
|
|
114
101
|
* generated symmetric key, which is then encrypted for the subject. The certificate
|
|
115
102
|
* can also includes a revocation outpoint to manage potential revocation.
|
|
116
103
|
*
|
|
117
|
-
* @param {
|
|
104
|
+
* @param {ProtoWallet} certifierWallet - The wallet of the certifier, used to sign the certificate and encrypt field keys.
|
|
118
105
|
* @param {WalletCounterparty} subject - The subject for whom the certificate is issued.
|
|
119
106
|
* @param {Record<CertificateFieldNameUnder50Bytes, string>} fields - Unencrypted certificate fields to include, with their names and values.
|
|
120
107
|
* @param {string} certificateType - The type of certificate being issued.
|
|
@@ -125,31 +112,74 @@ export class MasterCertificate extends Certificate {
|
|
|
125
112
|
*
|
|
126
113
|
* @throws {Error} Throws an error if any operation (e.g., encryption, signing) fails during certificate issuance.
|
|
127
114
|
*/
|
|
128
|
-
static async issueCertificateForSubject(certifierWallet, subject, fields, certificateType, getRevocationOutpoint = async (serialNumber) => { return 'Certificate revocation not tracked.'; }) {
|
|
129
|
-
// 1. Generate serialNumber
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const masterKeyringForSubject = {};
|
|
133
|
-
// 2. For each field, generate a random key -> encrypt field -> encrypt key
|
|
134
|
-
for (const [fieldName, fieldValue] of Object.entries(fields)) {
|
|
135
|
-
const fieldSymmetricKey = SymmetricKey.fromRandom();
|
|
136
|
-
const encryptedFieldValue = fieldSymmetricKey.encrypt(Utils.toArray(fieldValue, 'utf8'));
|
|
137
|
-
encryptedCertificateFields[fieldName] = Utils.toBase64(encryptedFieldValue);
|
|
138
|
-
const { ciphertext: encryptedFieldRevelationKey } = await certifierWallet.encrypt({
|
|
139
|
-
plaintext: fieldSymmetricKey.toArray(),
|
|
140
|
-
...Certificate.getCertificateFieldEncryptionDetails(serialNumber, fieldName),
|
|
141
|
-
counterparty: subject
|
|
142
|
-
});
|
|
143
|
-
masterKeyringForSubject[fieldName] = Utils.toBase64(encryptedFieldRevelationKey);
|
|
115
|
+
static async issueCertificateForSubject(certifierWallet, subject, fields, certificateType, getRevocationOutpoint = async (serialNumber) => { return 'Certificate revocation not tracked.'; }, serialNumber) {
|
|
116
|
+
// 1. Generate a random serialNumber if not provided
|
|
117
|
+
if (!serialNumber) {
|
|
118
|
+
serialNumber = Utils.toBase64(Random(32));
|
|
144
119
|
}
|
|
120
|
+
// 2. Create encrypted certificate fields and associated master keyring
|
|
121
|
+
const { certificateFields, masterKeyring } = await this.createCertificateFields(certifierWallet, subject, fields);
|
|
145
122
|
// 3. Obtain a revocation outpoint (ex. certifier can call wallet.createAction())
|
|
146
123
|
const revocationOutpoint = await getRevocationOutpoint(serialNumber);
|
|
147
124
|
// TODO: Validate revocation outpoint format
|
|
148
125
|
// 4. Create new MasterCertificate instance
|
|
149
|
-
const certificate = new MasterCertificate(certificateType, serialNumber, subject, (await certifierWallet.getPublicKey({ identityKey: true })).publicKey, revocationOutpoint,
|
|
126
|
+
const certificate = new MasterCertificate(certificateType, serialNumber, subject, (await certifierWallet.getPublicKey({ identityKey: true })).publicKey, revocationOutpoint, certificateFields, masterKeyring);
|
|
150
127
|
// 5. Sign and return the new MasterCertificate certifying the subject.
|
|
151
128
|
await certificate.sign(certifierWallet);
|
|
152
129
|
return certificate;
|
|
153
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Decrypts all fields in the MasterCertificate using the subject's or certifier's wallet.
|
|
133
|
+
*
|
|
134
|
+
* This method allows the subject or certifier to decrypt the `masterKeyring` and retrieve
|
|
135
|
+
* the encryption keys for each field, which are then used to decrypt the corresponding field values.
|
|
136
|
+
* The counterparty used for decryption depends on how the certificate fields were created:
|
|
137
|
+
* - If the certificate is self-signed, the counterparty should be set to 'self'.
|
|
138
|
+
* - Otherwise, the counterparty should always be the other party involved in the certificate issuance process (the subject or certifier).
|
|
139
|
+
*
|
|
140
|
+
* @param {ProtoWallet} subjectOrCertifierWallet - The wallet of the subject or certifier, used to decrypt the master keyring and field values.
|
|
141
|
+
* @param {Record<CertificateFieldNameUnder50Bytes, Base64String>} masterKeyring - A record containing encrypted keys for each field.
|
|
142
|
+
* @param {Record<CertificateFieldNameUnder50Bytes, Base64String>} fields - A record of encrypted field names and their values.
|
|
143
|
+
* @param {WalletCounterparty} counterparty - The counterparty responsible for creating or signing the certificate. For self-signed certificates, use 'self'.
|
|
144
|
+
* @returns {Promise<Record<CertificateFieldNameUnder50Bytes, string>>} A promise resolving to a record of field names and their decrypted values in plaintext.
|
|
145
|
+
*
|
|
146
|
+
* @throws {Error} Throws an error if the `masterKeyring` is invalid or if decryption fails for any field.
|
|
147
|
+
*/
|
|
148
|
+
static async decryptFields(subjectOrCertifierWallet, masterKeyring, fields, counterparty) {
|
|
149
|
+
if (!masterKeyring || Object.keys(masterKeyring).length === 0) {
|
|
150
|
+
throw new Error('A MasterCertificate must have a valid masterKeyring!');
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
const decryptedFields = {};
|
|
154
|
+
// Note: we want to iterate through all fields, not just masterKeyring keys/value pairs.
|
|
155
|
+
for (const fieldName of Object.keys(fields)) {
|
|
156
|
+
decryptedFields[fieldName] = (await this.decryptField(subjectOrCertifierWallet, masterKeyring, fieldName, fields[fieldName], counterparty)).decryptedFieldValue;
|
|
157
|
+
}
|
|
158
|
+
return decryptedFields;
|
|
159
|
+
}
|
|
160
|
+
catch (e) {
|
|
161
|
+
throw new Error('Failed to decrypt all master certificate fields.');
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
static async decryptField(subjectOrCertifierWallet, masterKeyring, fieldName, fieldValue, counterparty, originator) {
|
|
165
|
+
if (!masterKeyring || Object.keys(masterKeyring).length === 0) {
|
|
166
|
+
throw new Error('A MasterCertificate must have a valid masterKeyring!');
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
const { plaintext: fieldRevelationKey } = await subjectOrCertifierWallet.decrypt({
|
|
170
|
+
ciphertext: Utils.toArray(masterKeyring[fieldName], 'base64'),
|
|
171
|
+
...Certificate.getCertificateFieldEncryptionDetails(fieldName), // Only fieldName used on MasterCertificate
|
|
172
|
+
counterparty
|
|
173
|
+
}, originator);
|
|
174
|
+
const decryptedFieldValue = new SymmetricKey(fieldRevelationKey).decrypt(Utils.toArray(fieldValue, 'base64'));
|
|
175
|
+
return {
|
|
176
|
+
fieldRevelationKey,
|
|
177
|
+
decryptedFieldValue: Utils.toUTF8(decryptedFieldValue)
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
catch (e) {
|
|
181
|
+
throw new Error('Failed to decrypt certificate field!');
|
|
182
|
+
}
|
|
183
|
+
}
|
|
154
184
|
}
|
|
155
185
|
//# sourceMappingURL=MasterCertificate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MasterCertificate.js","sourceRoot":"","sources":["../../../../../src/auth/certificates/MasterCertificate.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,KAAK,EAML,MAAM,
|
|
1
|
+
{"version":3,"file":"MasterCertificate.js","sourceRoot":"","sources":["../../../../../src/auth/certificates/MasterCertificate.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,KAAK,EAML,MAAM,EAIP,MAAM,iBAAiB,CAAA;AACxB,OAAO,WAAW,MAAM,kBAAkB,CAAA;AAO1C;;;;;;;GAOG;AACH,MAAM,OAAO,iBAAkB,SAAQ,WAAW;IAShD,aAAa,CAAwD;IAErE,YACE,IAAkB,EAClB,YAA0B,EAC1B,OAAkB,EAClB,SAAoB,EACpB,kBAAkC,EAClC,MAA8D,EAC9D,aAAqE,EACrE,SAAqB;QAErB,KAAK,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;QAEpF,4FAA4F;QAC5F,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5C,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC9B,MAAM,IAAI,KAAK,CACb,gFAAgF,SAAS,IAAI,CAC9F,CAAA;YACH,CAAC;QACH,CAAC;QAED,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;IACpC,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAClC,aAA0B,EAC1B,kBAAsC,EACtC,MAAwD,EACxD,UAAoD;QAEpD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CACvB,wBAAqC,EACrC,aAAqE,EACrE,SAAuB,EACvB,UAAwB,EACxB,YAAgC,EAChC,UAAoD;QAEpD,IAAI,CAAC,aAAa,IAAI,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC9D,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAA;QACzE,CAAC;QACD,IAAI,CAAC;YACH,MAAM,EAAE,SAAS,EAAE,kBAAkB,EAAE,GAAG,MAAM,wBAAwB,CAAC,OAAO,CAAC;gBAC/E,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC;gBAC7D,GAAG,WAAW,CAAC,oCAAoC,CAAC,SAAS,CAAC,EAAE,2CAA2C;gBAC3G,YAAY;aACb,EAAE,UAAU,CAAC,CAAA;YAEd,MAAM,mBAAmB,GAAG,IAAI,YAAY,CAAC,kBAAkB,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAA;YAC7G,OAAO;gBACL,kBAAkB;gBAClB,mBAAmB,EAAE,KAAK,CAAC,MAAM,CAAC,mBAA+B,CAAC;aACnE,CAAA;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAA;QACzD,CAAC;IACH,CAAC;CACF"}
|
|
@@ -7,14 +7,14 @@ import Certificate from './Certificate.js';
|
|
|
7
7
|
export class VerifiableCertificate extends Certificate {
|
|
8
8
|
keyring;
|
|
9
9
|
decryptedFields;
|
|
10
|
-
constructor(type, serialNumber, subject, certifier, revocationOutpoint, fields,
|
|
10
|
+
constructor(type, serialNumber, subject, certifier, revocationOutpoint, fields, keyring, signature, decryptedFields) {
|
|
11
11
|
super(type, serialNumber, subject, certifier, revocationOutpoint, fields, signature);
|
|
12
12
|
this.keyring = keyring;
|
|
13
13
|
this.decryptedFields = decryptedFields;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Decrypts selectively revealed certificate fields using the provided keyring and verifier wallet
|
|
17
|
-
* @param {
|
|
17
|
+
* @param {ProtoWallet} verifierWallet - The wallet instance of the certificate's verifier, used to decrypt field keys.
|
|
18
18
|
* @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.
|
|
19
19
|
* @throws {Error} Throws an error if any of the decryption operations fail, with a message indicating the failure context.
|
|
20
20
|
*/
|
|
@@ -27,7 +27,7 @@ export class VerifiableCertificate extends Certificate {
|
|
|
27
27
|
for (const fieldName in this.keyring) {
|
|
28
28
|
const { plaintext: fieldRevelationKey } = await verifierWallet.decrypt({
|
|
29
29
|
ciphertext: Utils.toArray(this.keyring[fieldName], 'base64'),
|
|
30
|
-
...Certificate.getCertificateFieldEncryptionDetails(this.serialNumber
|
|
30
|
+
...Certificate.getCertificateFieldEncryptionDetails(fieldName, this.serialNumber),
|
|
31
31
|
counterparty: this.subject
|
|
32
32
|
});
|
|
33
33
|
const fieldValue = new SymmetricKey(fieldRevelationKey).decrypt(Utils.toArray(this.fields[fieldName], 'base64'));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VerifiableCertificate.js","sourceRoot":"","sources":["../../../../../src/auth/certificates/VerifiableCertificate.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,KAAK,
|
|
1
|
+
{"version":3,"file":"VerifiableCertificate.js","sourceRoot":"","sources":["../../../../../src/auth/certificates/VerifiableCertificate.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,KAAK,EAON,MAAM,iBAAiB,CAAA;AACxB,OAAO,WAAW,MAAM,kBAAkB,CAAA;AAE1C;;;GAGG;AACH,MAAM,OAAO,qBAAsB,SAAQ,WAAW;IASpD,OAAO,CAAkD;IACzD,eAAe,CAAyD;IAExE,YACE,IAAkB,EAClB,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ACnE,CAAC;YACD,OAAO,eAAe,CAAA;QACxB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,4EAA4E,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAA;QAC/I,CAAC;IACH,CAAC;CACF"}
|
|
@@ -21,7 +21,7 @@ export const getVerifiableCertificates = async (wallet, requestedCertificates, v
|
|
|
21
21
|
fieldsToReveal: requestedCertificates.types[certificate.type],
|
|
22
22
|
verifier: verifierIdentityKey
|
|
23
23
|
});
|
|
24
|
-
return new VerifiableCertificate(certificate.type, certificate.serialNumber, certificate.subject, certificate.certifier, certificate.revocationOutpoint, certificate.fields, certificate.signature
|
|
24
|
+
return new VerifiableCertificate(certificate.type, certificate.serialNumber, certificate.subject, certificate.certifier, certificate.revocationOutpoint, certificate.fields, keyringForVerifier, certificate.signature);
|
|
25
25
|
}));
|
|
26
26
|
};
|
|
27
27
|
//# sourceMappingURL=getVerifiableCertificates.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getVerifiableCertificates.js","sourceRoot":"","sources":["../../../../../src/auth/utils/getVerifiableCertificates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAA;AAIhF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,EAAE,MAAuB,EAAE,qBAA8C,EAAE,mBAA2B,EAAoC,EAAE;IACxL,qCAAqC;IACrC,2EAA2E;IAC3E,MAAM,oBAAoB,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC;QACzD,UAAU,EAAE,qBAAqB,CAAC,UAAU;QAC5C,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC;KAChD,CAAC,CAAA;IAEF,4FAA4F;IAC5F,OAAO,MAAM,OAAO,CAAC,GAAG,CACtB,oBAAoB,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAC,WAAW,EAAC,EAAE;QACxD,MAAM,EAAE,kBAAkB,EAAE,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC;YAC3D,WAAW;YACX,cAAc,EAAE,qBAAqB,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC;YAC7D,QAAQ,EAAE,mBAAmB;SAC9B,CAAC,CAAA;QACF,OAAO,IAAI,qBAAqB,CAC9B,WAAW,CAAC,IAAI,EAChB,WAAW,CAAC,YAAY,EACxB,WAAW,CAAC,OAAO,EACnB,WAAW,CAAC,SAAS,EACrB,WAAW,CAAC,kBAAkB,EAC9B,WAAW,CAAC,MAAM,EAClB,WAAW,CAAC,SAAS,
|
|
1
|
+
{"version":3,"file":"getVerifiableCertificates.js","sourceRoot":"","sources":["../../../../../src/auth/utils/getVerifiableCertificates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAA;AAIhF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,EAAE,MAAuB,EAAE,qBAA8C,EAAE,mBAA2B,EAAoC,EAAE;IACxL,qCAAqC;IACrC,2EAA2E;IAC3E,MAAM,oBAAoB,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC;QACzD,UAAU,EAAE,qBAAqB,CAAC,UAAU;QAC5C,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC;KAChD,CAAC,CAAA;IAEF,4FAA4F;IAC5F,OAAO,MAAM,OAAO,CAAC,GAAG,CACtB,oBAAoB,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAC,WAAW,EAAC,EAAE;QACxD,MAAM,EAAE,kBAAkB,EAAE,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC;YAC3D,WAAW;YACX,cAAc,EAAE,qBAAqB,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC;YAC7D,QAAQ,EAAE,mBAAmB;SAC9B,CAAC,CAAA;QACF,OAAO,IAAI,qBAAqB,CAC9B,WAAW,CAAC,IAAI,EAChB,WAAW,CAAC,YAAY,EACxB,WAAW,CAAC,OAAO,EACnB,WAAW,CAAC,SAAS,EACrB,WAAW,CAAC,kBAAkB,EAC9B,WAAW,CAAC,MAAM,EAClB,kBAAkB,EAClB,WAAW,CAAC,SAAS,CACtB,CAAA;IACH,CAAC,CAAC,CAAC,CAAA;AACP,CAAC,CAAA"}
|
|
@@ -13,7 +13,7 @@ export const validateCertificates = async (verifierWallet, message, certificates
|
|
|
13
13
|
throw new Error(`The subject of one of your certificates ("${incomingCert.subject}") is not the same as the request sender ("${message.identityKey}").`);
|
|
14
14
|
}
|
|
15
15
|
// Verify Certificate structure and signature
|
|
16
|
-
const certToVerify = new VerifiableCertificate(incomingCert.type, incomingCert.serialNumber, incomingCert.subject, incomingCert.certifier, incomingCert.revocationOutpoint, incomingCert.fields, incomingCert.
|
|
16
|
+
const certToVerify = new VerifiableCertificate(incomingCert.type, incomingCert.serialNumber, incomingCert.subject, incomingCert.certifier, incomingCert.revocationOutpoint, incomingCert.fields, incomingCert.keyring, incomingCert.signature);
|
|
17
17
|
const isValidCert = await certToVerify.verify();
|
|
18
18
|
if (!isValidCert) {
|
|
19
19
|
throw new Error(`The signature for the certificate with serial number ${certToVerify.serialNumber} is invalid!`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateCertificates.js","sourceRoot":"","sources":["../../../../../src/auth/utils/validateCertificates.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAA;AAEhF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EAAE,cAA+B,EAAE,OAAoB,EAAE,qBAA+C,EAAiB,EAAE;IAClK,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,YAAmC,EAAE,EAAE;QACvF,IAAI,YAAY,CAAC,OAAO,KAAK,OAAO,CAAC,WAAW,EAAE,CAAC;YACjD,MAAM,IAAI,KAAK,CAAC,6CAA6C,YAAY,CAAC,OAAO,8CAA8C,OAAO,CAAC,WAAW,KAAK,CAAC,CAAA;QAC1J,CAAC;QAED,6CAA6C;QAC7C,MAAM,YAAY,GAAG,IAAI,qBAAqB,CAC5C,YAAY,CAAC,IAAI,EACjB,YAAY,CAAC,YAAY,EACzB,YAAY,CAAC,OAAO,EACpB,YAAY,CAAC,SAAS,EACtB,YAAY,CAAC,kBAAkB,EAC/B,YAAY,CAAC,MAAM,EACnB,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"validateCertificates.js","sourceRoot":"","sources":["../../../../../src/auth/utils/validateCertificates.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAA;AAEhF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EAAE,cAA+B,EAAE,OAAoB,EAAE,qBAA+C,EAAiB,EAAE;IAClK,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,YAAmC,EAAE,EAAE;QACvF,IAAI,YAAY,CAAC,OAAO,KAAK,OAAO,CAAC,WAAW,EAAE,CAAC;YACjD,MAAM,IAAI,KAAK,CAAC,6CAA6C,YAAY,CAAC,OAAO,8CAA8C,OAAO,CAAC,WAAW,KAAK,CAAC,CAAA;QAC1J,CAAC;QAED,6CAA6C;QAC7C,MAAM,YAAY,GAAG,IAAI,qBAAqB,CAC5C,YAAY,CAAC,IAAI,EACjB,YAAY,CAAC,YAAY,EACzB,YAAY,CAAC,OAAO,EACpB,YAAY,CAAC,SAAS,EACtB,YAAY,CAAC,kBAAkB,EAC/B,YAAY,CAAC,MAAM,EACnB,YAAY,CAAC,OAAO,EACpB,YAAY,CAAC,SAAS,CACvB,CAAA;QACD,MAAM,WAAW,GAAG,MAAM,YAAY,CAAC,MAAM,EAAE,CAAA;QAC/C,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,wDAAwD,YAAY,CAAC,YAAY,cAAc,CAAC,CAAA;QAClH,CAAC;QAED,2EAA2E;QAC3E,IAAI,qBAAqB,EAAE,CAAC;YAC1B,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,qBAAqB,CAAA;YAEnD,0BAA0B;YAC1B,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,CAAC;gBACjD,MAAM,IAAI,KAAK,CAAC,kCAAkC,YAAY,CAAC,YAAY,kCAAkC,YAAY,CAAC,SAAS,EAAE,CAAC,CAAA;YACxI,CAAC;YAED,wCAAwC;YACxC,MAAM,eAAe,GAAG,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAA;YAChD,IAAI,CAAC,eAAe,EAAE,CAAC;gBACrB,MAAM,IAAI,KAAK,CAAC,yBAAyB,YAAY,CAAC,IAAI,oBAAoB,CAAC,CAAA;YACjF,CAAC;QACH,CAAC;QAED,4BAA4B;QAC5B,MAAM,YAAY,CAAC,aAAa,CAAC,cAAc,CAAC,CAAA;IAClD,CAAC,CAAC,CAAC,CAAA;AACL,CAAC,CAAA"}
|
|
@@ -15,7 +15,7 @@ export class ProtoWallet {
|
|
|
15
15
|
}
|
|
16
16
|
this.keyDeriver = rootKeyOrKeyDeriver;
|
|
17
17
|
}
|
|
18
|
-
async getPublicKey(args) {
|
|
18
|
+
async getPublicKey(args, originator) {
|
|
19
19
|
if (args.identityKey) {
|
|
20
20
|
return { publicKey: this.keyDeriver.rootKey.toPublicKey().toString() };
|
|
21
21
|
}
|
|
@@ -30,7 +30,7 @@ export class ProtoWallet {
|
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
async revealCounterpartyKeyLinkage(args) {
|
|
33
|
+
async revealCounterpartyKeyLinkage(args, originator) {
|
|
34
34
|
const { publicKey: identityKey } = await this.getPublicKey({ identityKey: true });
|
|
35
35
|
const linkage = this.keyDeriver.revealCounterpartySecret(args.counterparty);
|
|
36
36
|
const linkageProof = new Schnorr().generateProof(this.keyDeriver.rootKey, this.keyDeriver.rootKey.toPublicKey(), PublicKey.fromString(args.counterparty), Point.fromDER(linkage));
|
|
@@ -61,7 +61,7 @@ export class ProtoWallet {
|
|
|
61
61
|
encryptedLinkageProof
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
|
-
async revealSpecificKeyLinkage(args) {
|
|
64
|
+
async revealSpecificKeyLinkage(args, originator) {
|
|
65
65
|
const { publicKey: identityKey } = await this.getPublicKey({ identityKey: true });
|
|
66
66
|
const linkage = this.keyDeriver.revealSpecificSecret(args.counterparty, args.protocolID, args.keyID);
|
|
67
67
|
const { ciphertext: encryptedLinkage } = await this.encrypt({
|
|
@@ -87,19 +87,19 @@ export class ProtoWallet {
|
|
|
87
87
|
proofType: 0
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
|
-
async encrypt(args) {
|
|
90
|
+
async encrypt(args, originator) {
|
|
91
91
|
const key = this.keyDeriver.deriveSymmetricKey(args.protocolID, args.keyID, args.counterparty || 'self');
|
|
92
92
|
return { ciphertext: key.encrypt(args.plaintext) };
|
|
93
93
|
}
|
|
94
|
-
async decrypt(args) {
|
|
94
|
+
async decrypt(args, originator) {
|
|
95
95
|
const key = this.keyDeriver.deriveSymmetricKey(args.protocolID, args.keyID, args.counterparty || 'self');
|
|
96
96
|
return { plaintext: key.decrypt(args.ciphertext) };
|
|
97
97
|
}
|
|
98
|
-
async createHmac(args) {
|
|
98
|
+
async createHmac(args, originator) {
|
|
99
99
|
const key = this.keyDeriver.deriveSymmetricKey(args.protocolID, args.keyID, args.counterparty || 'self');
|
|
100
100
|
return { hmac: Hash.sha256hmac(key.toArray(), args.data) };
|
|
101
101
|
}
|
|
102
|
-
async verifyHmac(args) {
|
|
102
|
+
async verifyHmac(args, originator) {
|
|
103
103
|
const key = this.keyDeriver.deriveSymmetricKey(args.protocolID, args.keyID, args.counterparty || 'self');
|
|
104
104
|
const valid = Hash.sha256hmac(key.toArray(), args.data).toString() === args.hmac.toString();
|
|
105
105
|
if (!valid) {
|
|
@@ -109,7 +109,7 @@ export class ProtoWallet {
|
|
|
109
109
|
}
|
|
110
110
|
return { valid };
|
|
111
111
|
}
|
|
112
|
-
async createSignature(args) {
|
|
112
|
+
async createSignature(args, originator) {
|
|
113
113
|
if (!args.hashToDirectlySign && !args.data) {
|
|
114
114
|
throw new Error('args.data or args.hashToDirectlySign must be valid');
|
|
115
115
|
}
|
|
@@ -117,7 +117,7 @@ export class ProtoWallet {
|
|
|
117
117
|
const key = this.keyDeriver.derivePrivateKey(args.protocolID, args.keyID, args.counterparty || 'anyone');
|
|
118
118
|
return { signature: ECDSA.sign(new BigNumber(hash), key, true).toDER() };
|
|
119
119
|
}
|
|
120
|
-
async verifySignature(args) {
|
|
120
|
+
async verifySignature(args, originator) {
|
|
121
121
|
if (!args.hashToDirectlyVerify && !args.data) {
|
|
122
122
|
throw new Error('args.data or args.hashToDirectlyVerify must be valid');
|
|
123
123
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProtoWallet.js","sourceRoot":"","sources":["../../../../src/wallet/ProtoWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAiB,MAAM,iBAAiB,CAAA;AAC3D,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAc,MAAM,wBAAwB,CAAA;AA0BjH;;;;;;GAMG;AACH,MAAM,OAAO,WAAW;IACtB,UAAU,
|
|
1
|
+
{"version":3,"file":"ProtoWallet.js","sourceRoot":"","sources":["../../../../src/wallet/ProtoWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAiB,MAAM,iB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