@bsv/sdk 1.2.20 → 1.2.22
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 +3 -3
- package/dist/cjs/src/auth/Peer.js +536 -0
- package/dist/cjs/src/auth/Peer.js.map +1 -0
- package/dist/cjs/src/auth/SessionManager.js +66 -0
- package/dist/cjs/src/auth/SessionManager.js.map +1 -0
- package/dist/cjs/src/auth/{Certificate.js → certificates/Certificate.js} +22 -26
- package/dist/cjs/src/auth/certificates/Certificate.js.map +1 -0
- package/dist/cjs/src/auth/certificates/MasterCertificate.js +79 -0
- package/dist/cjs/src/auth/certificates/MasterCertificate.js.map +1 -0
- package/dist/cjs/src/auth/certificates/VerifiableCertificate.js +49 -0
- package/dist/cjs/src/auth/certificates/VerifiableCertificate.js.map +1 -0
- package/dist/cjs/src/auth/certificates/index.js +25 -0
- package/dist/cjs/src/auth/certificates/index.js.map +1 -0
- package/dist/cjs/src/auth/clients/AuthFetch.js +411 -0
- package/dist/cjs/src/auth/clients/AuthFetch.js.map +1 -0
- package/dist/cjs/src/auth/clients/index.js +18 -0
- package/dist/cjs/src/auth/clients/index.js.map +1 -0
- package/dist/cjs/src/auth/index.js +20 -5
- package/dist/cjs/src/auth/index.js.map +1 -1
- package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js +259 -0
- package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js.map +1 -0
- package/dist/cjs/src/auth/transports/index.js +18 -0
- package/dist/cjs/src/auth/transports/index.js.map +1 -0
- package/dist/cjs/src/auth/types.js +3 -0
- package/dist/cjs/src/auth/types.js.map +1 -0
- package/dist/cjs/src/auth/utils/certificateHelpers.js +51 -0
- package/dist/cjs/src/auth/utils/certificateHelpers.js.map +1 -0
- package/dist/cjs/src/auth/utils/createNonce.js +19 -0
- package/dist/cjs/src/auth/utils/createNonce.js.map +1 -0
- package/dist/cjs/src/auth/utils/getVerifiableCertificates.js +31 -0
- package/dist/cjs/src/auth/utils/getVerifiableCertificates.js.map +1 -0
- package/dist/cjs/src/auth/utils/index.js +22 -0
- package/dist/cjs/src/auth/utils/index.js.map +1 -0
- package/dist/cjs/src/auth/utils/validateCertificates.js +42 -0
- package/dist/cjs/src/auth/utils/validateCertificates.js.map +1 -0
- package/dist/cjs/src/auth/utils/verifyNonce.js +27 -0
- package/dist/cjs/src/auth/utils/verifyNonce.js.map +1 -0
- package/dist/cjs/src/primitives/Point.js +1 -1
- package/dist/cjs/src/primitives/Point.js.map +1 -1
- package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js +1 -1
- package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
- package/dist/cjs/src/wallet/substrates/WalletWireTransceiver.js +148 -148
- package/dist/cjs/src/wallet/substrates/WalletWireTransceiver.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/auth/Peer.js +533 -0
- package/dist/esm/src/auth/Peer.js.map +1 -0
- package/dist/esm/src/auth/SessionManager.js +63 -0
- package/dist/esm/src/auth/SessionManager.js.map +1 -0
- package/dist/esm/src/auth/{Certificate.js → certificates/Certificate.js} +1 -2
- package/dist/esm/src/auth/certificates/Certificate.js.map +1 -0
- package/dist/esm/src/auth/certificates/MasterCertificate.js +73 -0
- package/dist/esm/src/auth/certificates/MasterCertificate.js.map +1 -0
- package/dist/esm/src/auth/certificates/VerifiableCertificate.js +44 -0
- package/dist/esm/src/auth/certificates/VerifiableCertificate.js.map +1 -0
- package/dist/esm/src/auth/certificates/index.js +4 -0
- package/dist/esm/src/auth/certificates/index.js.map +1 -0
- package/dist/esm/src/auth/clients/AuthFetch.js +409 -0
- package/dist/esm/src/auth/clients/AuthFetch.js.map +1 -0
- package/dist/esm/src/auth/clients/index.js +2 -0
- package/dist/esm/src/auth/clients/index.js.map +1 -0
- package/dist/esm/src/auth/index.js +7 -1
- package/dist/esm/src/auth/index.js.map +1 -1
- package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js +258 -0
- package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js.map +1 -0
- package/dist/esm/src/auth/transports/index.js +2 -0
- package/dist/esm/src/auth/transports/index.js.map +1 -0
- package/dist/esm/src/auth/types.js +2 -0
- package/dist/esm/src/auth/types.js.map +1 -0
- package/dist/esm/src/auth/utils/certificateHelpers.js +47 -0
- package/dist/esm/src/auth/utils/certificateHelpers.js.map +1 -0
- package/dist/esm/src/auth/utils/createNonce.js +16 -0
- package/dist/esm/src/auth/utils/createNonce.js.map +1 -0
- package/dist/esm/src/auth/utils/getVerifiableCertificates.js +27 -0
- package/dist/esm/src/auth/utils/getVerifiableCertificates.js.map +1 -0
- package/dist/esm/src/auth/utils/index.js +6 -0
- package/dist/esm/src/auth/utils/index.js.map +1 -0
- package/dist/esm/src/auth/utils/validateCertificates.js +38 -0
- package/dist/esm/src/auth/utils/validateCertificates.js.map +1 -0
- package/dist/esm/src/auth/utils/verifyNonce.js +24 -0
- package/dist/esm/src/auth/utils/verifyNonce.js.map +1 -0
- package/dist/esm/src/primitives/Point.js +1 -1
- package/dist/esm/src/primitives/Point.js.map +1 -1
- package/dist/esm/src/wallet/substrates/WalletWireProcessor.js +1 -1
- package/dist/esm/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
- package/dist/esm/src/wallet/substrates/WalletWireTransceiver.js +1 -1
- package/dist/esm/src/wallet/substrates/WalletWireTransceiver.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/auth/Peer.d.ts +193 -0
- package/dist/types/src/auth/Peer.d.ts.map +1 -0
- package/dist/types/src/auth/SessionManager.d.ts +42 -0
- package/dist/types/src/auth/SessionManager.d.ts.map +1 -0
- package/dist/types/src/auth/{Certificate.d.ts → certificates/Certificate.d.ts} +1 -1
- package/dist/types/src/auth/certificates/Certificate.d.ts.map +1 -0
- package/dist/types/src/auth/certificates/MasterCertificate.d.ts +38 -0
- package/dist/types/src/auth/certificates/MasterCertificate.d.ts.map +1 -0
- package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts +26 -0
- package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts.map +1 -0
- package/dist/types/src/auth/certificates/index.d.ts +4 -0
- package/dist/types/src/auth/certificates/index.d.ts.map +1 -0
- package/dist/types/src/auth/clients/AuthFetch.d.ts +87 -0
- package/dist/types/src/auth/clients/AuthFetch.d.ts.map +1 -0
- package/dist/types/src/auth/clients/index.d.ts +2 -0
- package/dist/types/src/auth/clients/index.d.ts.map +1 -0
- package/dist/types/src/auth/index.d.ts +7 -1
- package/dist/types/src/auth/index.d.ts.map +1 -1
- package/dist/types/src/auth/transports/SimplifiedFetchTransport.d.ts +51 -0
- package/dist/types/src/auth/transports/SimplifiedFetchTransport.d.ts.map +1 -0
- package/dist/types/src/auth/transports/index.d.ts +2 -0
- package/dist/types/src/auth/transports/index.d.ts.map +1 -0
- package/dist/types/src/auth/types.d.ts +31 -0
- package/dist/types/src/auth/types.d.ts.map +1 -0
- package/dist/types/src/auth/utils/certificateHelpers.d.ts +26 -0
- package/dist/types/src/auth/utils/certificateHelpers.d.ts.map +1 -0
- package/dist/types/src/auth/utils/createNonce.d.ts +8 -0
- package/dist/types/src/auth/utils/createNonce.d.ts.map +1 -0
- package/dist/types/src/auth/utils/getVerifiableCertificates.d.ts +13 -0
- package/dist/types/src/auth/utils/getVerifiableCertificates.d.ts.map +1 -0
- package/dist/types/src/auth/utils/index.d.ts +6 -0
- package/dist/types/src/auth/utils/index.d.ts.map +1 -0
- package/dist/types/src/auth/utils/validateCertificates.d.ts +12 -0
- package/dist/types/src/auth/utils/validateCertificates.d.ts.map +1 -0
- package/dist/types/src/auth/utils/verifyNonce.d.ts +9 -0
- package/dist/types/src/auth/utils/verifyNonce.d.ts.map +1 -0
- package/dist/types/src/primitives/Point.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/docs/README.md +1 -0
- package/docs/auth.md +1193 -0
- package/package.json +13 -3
- package/src/auth/Peer.ts +600 -0
- package/src/auth/SessionManager.ts +71 -0
- package/src/auth/__tests/Peer.test.ts +599 -0
- package/src/auth/__tests/SessionManager.test.ts +87 -0
- package/src/auth/{Certificate.ts → certificates/Certificate.ts} +15 -8
- package/src/auth/certificates/MasterCertificate.ts +106 -0
- package/src/auth/certificates/VerifiableCertificate.ts +73 -0
- package/src/auth/certificates/__tests/Certificate.test.ts +282 -0
- package/src/auth/certificates/index.ts +3 -0
- package/src/auth/clients/AuthFetch.ts +482 -0
- package/src/auth/clients/index.ts +1 -0
- package/src/auth/index.ts +7 -1
- package/src/auth/transports/SimplifiedFetchTransport.ts +288 -0
- package/src/auth/transports/index.ts +1 -0
- package/src/auth/types.ts +41 -0
- package/src/auth/utils/__tests/cryptononce.test.ts +84 -0
- package/src/auth/utils/__tests/getVerifiableCertificates.test.ts +126 -0
- package/src/auth/utils/__tests/validateCertificates.test.ts +142 -0
- package/src/auth/utils/certificateHelpers.ts +86 -0
- package/src/auth/utils/createNonce.ts +16 -0
- package/src/auth/utils/getVerifiableCertificates.ts +40 -0
- package/src/auth/utils/index.ts +5 -0
- package/src/auth/utils/validateCertificates.ts +54 -0
- package/src/auth/utils/verifyNonce.ts +27 -0
- package/src/primitives/Point.ts +59 -59
- package/src/wallet/substrates/WalletWireProcessor.ts +1 -1
- package/src/wallet/substrates/WalletWireTransceiver.ts +1 -1
- package/dist/cjs/src/auth/Certificate.js.map +0 -1
- package/dist/esm/src/auth/Certificate.js.map +0 -1
- package/dist/types/src/auth/Certificate.d.ts.map +0 -1
- package/src/auth/__tests/Certificate.test.ts +0 -282
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { SymmetricKey, Utils } from '../../../mod.js';
|
|
2
|
+
import Certificate from './Certificate.js';
|
|
3
|
+
/**
|
|
4
|
+
* MasterCertificate extends the base Certificate class to manage a master keyring, enabling the creation of verifiable certificates.
|
|
5
|
+
*
|
|
6
|
+
* It allows for the selective disclosure of certificate fields by creating a `VerifiableCertificate` for a specific verifier.
|
|
7
|
+
* The `MasterCertificate` can securely decrypt each master key and re-encrypt it for a verifier, creating a customized
|
|
8
|
+
* keyring containing only the keys necessary for the verifier to access designated fields.
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
export class MasterCertificate extends Certificate {
|
|
12
|
+
masterKeyring;
|
|
13
|
+
constructor(type, serialNumber, subject, certifier, revocationOutpoint, fields, masterKeyring, signature) {
|
|
14
|
+
super(type, serialNumber, subject, certifier, revocationOutpoint, fields, signature);
|
|
15
|
+
this.masterKeyring = masterKeyring;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a verifiable certificate structure for a specific verifier, allowing them access to specified fields.
|
|
19
|
+
* This method decrypts the master field keys for each field specified in `fieldsToReveal` and re-encrypts them
|
|
20
|
+
* for the verifier's identity key. The resulting certificate structure includes only the fields intended to be
|
|
21
|
+
* revealed and a verifier-specific keyring for field decryption.
|
|
22
|
+
*
|
|
23
|
+
* @param {Wallet} subjectWallet - The wallet instance of the subject, used to decrypt and re-encrypt field keys.
|
|
24
|
+
* @param {string} verifierIdentityKey - The public identity key of the verifier who will receive access to the specified fields.
|
|
25
|
+
* @param {string[]} fieldsToReveal - An array of field names to be revealed to the verifier. Must be a subset of the certificate's fields.
|
|
26
|
+
* @param {string} [originator] - Optional originator identifier, used if additional context is needed for decryption and encryption operations.
|
|
27
|
+
* @returns {Promise<Object>} - A new certificate structure containing the original encrypted fields, the verifier-specific field decryption keyring, and essential certificate metadata.
|
|
28
|
+
* @throws {Error} Throws an error if:
|
|
29
|
+
* - fieldsToReveal is empty or a field in `fieldsToReveal` does not exist in the certificate.
|
|
30
|
+
* - The decrypted master field key fails to decrypt the corresponding field (indicating an invalid key).
|
|
31
|
+
*/
|
|
32
|
+
async createKeyringForVerifier(subjectWallet, verifierIdentityKey, fieldsToReveal, originator) {
|
|
33
|
+
if (!Array.isArray(fieldsToReveal)) {
|
|
34
|
+
throw new Error('fieldsToReveal must be an array of strings');
|
|
35
|
+
}
|
|
36
|
+
const fieldRevelationKeyring = {};
|
|
37
|
+
for (const fieldName of fieldsToReveal) {
|
|
38
|
+
// Make sure that fields to reveal is a subset of the certificate fields
|
|
39
|
+
if (!this.fields[fieldName]) {
|
|
40
|
+
throw new Error(`Fields to reveal must be a subset of the certificate fields. Missing the "${fieldName}" field.`);
|
|
41
|
+
}
|
|
42
|
+
// Create a keyID
|
|
43
|
+
const keyID = `${this.serialNumber} ${fieldName}`;
|
|
44
|
+
const encryptedMasterFieldKey = this.masterKeyring[fieldName];
|
|
45
|
+
// Decrypt the master field key
|
|
46
|
+
const { plaintext: masterFieldKey } = await subjectWallet.decrypt({
|
|
47
|
+
ciphertext: Utils.toArray(encryptedMasterFieldKey, 'base64'),
|
|
48
|
+
protocolID: [2, 'certificate field encryption'],
|
|
49
|
+
keyID,
|
|
50
|
+
counterparty: 'self'
|
|
51
|
+
}, originator);
|
|
52
|
+
// Verify that derived key actually decrypts requested field
|
|
53
|
+
try {
|
|
54
|
+
new SymmetricKey(masterFieldKey).decrypt(Utils.toArray(this.fields[fieldName], 'base64'));
|
|
55
|
+
}
|
|
56
|
+
catch (_) {
|
|
57
|
+
throw new Error(`Decryption of the "${fieldName}" field with its revelation key failed.`);
|
|
58
|
+
}
|
|
59
|
+
// Encrypt derived fieldRevelationKey for verifier
|
|
60
|
+
const { ciphertext: encryptedFieldRevelationKey } = await subjectWallet.encrypt({
|
|
61
|
+
plaintext: masterFieldKey,
|
|
62
|
+
protocolID: [2, 'certificate field encryption'],
|
|
63
|
+
keyID: `${this.serialNumber} ${fieldName}`,
|
|
64
|
+
counterparty: verifierIdentityKey
|
|
65
|
+
}, originator);
|
|
66
|
+
// Add encryptedFieldRevelationKey to fieldRevelationKeyring
|
|
67
|
+
fieldRevelationKeyring[fieldName] = Utils.toBase64(encryptedFieldRevelationKey);
|
|
68
|
+
}
|
|
69
|
+
// Return the field revelation keyring which can be used to create a verifiable certificate for a verifier.
|
|
70
|
+
return fieldRevelationKeyring;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=MasterCertificate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MasterCertificate.js","sourceRoot":"","sources":["../../../../../src/auth/certificates/MasterCertificate.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,KAAK,EAON,MAAM,iBAAiB,CAAA;AACxB,OAAO,WAAW,MAAM,kBAAkB,CAAA;AAE1C;;;;;;;GAOG;AACH,MAAM,OAAO,iBAAkB,SAAQ,WAAW;IAShD,aAAa,CAAkD;IAE/D,YACE,IAAkB,EAClB,YAA0B,EAC1B,OAAkB,EAClB,SAAoB,EACpB,kBAAkC,EAClC,MAAwD,EACxD,aAA+D,EAC/D,SAAqB;QAErB,KAAK,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;QACpF,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;IACpC,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,wBAAwB,CAAC,aAAqB,EAAE,mBAA2B,EAAE,cAAwB,EAAE,UAAmB;QAC9H,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;QAC/D,CAAC;QACD,MAAM,sBAAsB,GAAG,EAAE,CAAA;QACjC,KAAK,MAAM,SAAS,IAAI,cAAc,EAAE,CAAC;YACvC,wEAAwE;YACxE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC5B,MAAM,IAAI,KAAK,CAAC,6EAA6E,SAAS,UAAU,CAAC,CAAA;YACnH,CAAC;YAED,iBAAiB;YACjB,MAAM,KAAK,GAAG,GAAG,IAAI,CAAC,YAAY,IAAI,SAA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.js';
|
|
3
|
+
/**
|
|
4
|
+
* VerifiableCertificate extends the Certificate class, adding functionality to manage a verifier-specific keyring.
|
|
5
|
+
* This keyring allows selective decryption of certificate fields for authorized verifiers.
|
|
6
|
+
*/
|
|
7
|
+
export class VerifiableCertificate extends Certificate {
|
|
8
|
+
keyring;
|
|
9
|
+
decryptedFields;
|
|
10
|
+
constructor(type, serialNumber, subject, certifier, revocationOutpoint, fields, signature, keyring, decryptedFields) {
|
|
11
|
+
super(type, serialNumber, subject, certifier, revocationOutpoint, fields, signature);
|
|
12
|
+
this.keyring = keyring;
|
|
13
|
+
this.decryptedFields = decryptedFields;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Decrypts certificate fields using the provided keyring and verifier wallet
|
|
17
|
+
* @param {Wallet} verifierWallet - The wallet instance of the certificate's verifier, used to decrypt field keys.
|
|
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
|
+
* @throws {Error} Throws an error if any of the decryption operations fail, with a message indicating the failure context.
|
|
20
|
+
*/
|
|
21
|
+
async decryptFields(verifierWallet) {
|
|
22
|
+
if (!this.keyring || Object.keys(this.keyring).length === 0) {
|
|
23
|
+
throw new Error('A keyring is required to decrypt certificate fields for the verifier.');
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const decryptedFields = {};
|
|
27
|
+
for (const fieldName in this.keyring) {
|
|
28
|
+
const { plaintext: fieldRevelationKey } = await verifierWallet.decrypt({
|
|
29
|
+
ciphertext: Utils.toArray(this.keyring[fieldName], 'base64'),
|
|
30
|
+
protocolID: [2, 'certificate field encryption'],
|
|
31
|
+
keyID: `${this.serialNumber} ${fieldName}`,
|
|
32
|
+
counterparty: this.subject
|
|
33
|
+
});
|
|
34
|
+
const fieldValue = new SymmetricKey(fieldRevelationKey).decrypt(Utils.toArray(this.fields[fieldName], 'base64'));
|
|
35
|
+
decryptedFields[fieldName] = Utils.toUTF8(fieldValue);
|
|
36
|
+
}
|
|
37
|
+
return decryptedFields;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throw new Error(`Failed to decrypt certificate fields using keyring: ${error instanceof Error ? error.message : error}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=VerifiableCertificate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,YAA0B,EAC1B,OAAkB,EAClB,SAAoB,EACpB,kBAAkC,EAClC,MAAwD,EACxD,SAAqB,EACrB,OAA0D,EAC1D,eAAwE;QAExE,KAAK,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;QACpF,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;IACxC,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,aAAa,CAAC,cAAsB;QACxC,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC5D,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAA;QAC1F,CAAC;QACD,IAAI,CAAC;YACH,MAAM,eAAe,GAAG,EAAE,CAAA;YAC1B,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;gBACrC,MAAM,EAAE,SAAS,EAAE,kBAAkB,EAAE,GAAG,MAAM,cAAc,CAAC,OAAO,CAAC;oBACrE,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC;oBAC5D,UAAU,EAAE,CAAC,CAAC,EAAE,8BAA8B,CAAC;oBAC/C,KAAK,EAAE,GAAG,IAAI,CAAC,YAAY,IAAI,SAAS,EAAE;oBAC1C,YAAY,EAAE,IAAI,CAAC,OAAO;iBAC3B,CAAC,CAAA;gBAEF,MAAM,UAAU,GAAG,IAAI,YAAY,CAAC,kBAAkB,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAA;gBAChH,eAAe,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,UAAsB,CAAC,CAAA;YACnE,CAAC;YACD,OAAO,eAAe,CAAA;QACxB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,uDAAuD,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAA;QAC1H,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/auth/certificates/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACzD,cAAc,wBAAwB,CAAA;AACtC,cAAc,4BAA4B,CAAA"}
|
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import { Utils, Random, P2PKH, PublicKey } from '../../../mod.js';
|
|
2
|
+
import { Peer } from '../Peer.js';
|
|
3
|
+
import { SimplifiedFetchTransport } from '../transports/SimplifiedFetchTransport.js';
|
|
4
|
+
import { SessionManager } from '../SessionManager.js';
|
|
5
|
+
const PAYMENT_VERSION = '1.0';
|
|
6
|
+
/**
|
|
7
|
+
* AuthFetch provides a lightweight fetch client for interacting with servers
|
|
8
|
+
* over a simplified HTTP transport mechanism. It integrates session management, peer communication,
|
|
9
|
+
* and certificate handling to enable secure and mutually-authenticated requests.
|
|
10
|
+
*
|
|
11
|
+
* Additionally, it automatically handles 402 Payment Required responses by creating
|
|
12
|
+
* and sending BSV payment transactions when necessary.
|
|
13
|
+
*/
|
|
14
|
+
export class AuthFetch {
|
|
15
|
+
sessionManager;
|
|
16
|
+
wallet;
|
|
17
|
+
callbacks = {};
|
|
18
|
+
certificatesReceived = [];
|
|
19
|
+
requestedCertificates;
|
|
20
|
+
peers = {};
|
|
21
|
+
/**
|
|
22
|
+
* Constructs a new SimplifiedFetch instance.
|
|
23
|
+
* @param wallet - The wallet instance for signing and authentication.
|
|
24
|
+
* @param requestedCertificates - Optional set of certificates to request from peers.
|
|
25
|
+
*/
|
|
26
|
+
constructor(wallet, requestedCertificates, sessionManager) {
|
|
27
|
+
this.wallet = wallet;
|
|
28
|
+
this.requestedCertificates = requestedCertificates;
|
|
29
|
+
this.sessionManager = sessionManager || new SessionManager();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Mutually authenticates and sends a HTTP request to a server.
|
|
33
|
+
*
|
|
34
|
+
* 1) Attempt the request.
|
|
35
|
+
* 2) If 402 Payment Required, automatically create and send payment.
|
|
36
|
+
* 3) Return the final response.
|
|
37
|
+
*
|
|
38
|
+
* @param url - The URL to send the request to.
|
|
39
|
+
* @param config - Configuration options for the request, including method, headers, and body.
|
|
40
|
+
* @returns A promise that resolves with the server's response, structured as a Response-like object.
|
|
41
|
+
*
|
|
42
|
+
* @throws Will throw an error if unsupported headers are used or other validation fails.
|
|
43
|
+
*/
|
|
44
|
+
async fetch(url, config = {}) {
|
|
45
|
+
if (config.retryCounter) {
|
|
46
|
+
if (config.retryCounter <= 0) {
|
|
47
|
+
throw new Error('Request failed after maximum number of retries.');
|
|
48
|
+
}
|
|
49
|
+
config.retryCounter--;
|
|
50
|
+
}
|
|
51
|
+
const response = await new Promise(async (resolve, reject) => {
|
|
52
|
+
try {
|
|
53
|
+
// Apply defaults
|
|
54
|
+
const { method = 'GET', headers = {}, body } = config;
|
|
55
|
+
// Extract a base url
|
|
56
|
+
const parsedUrl = new URL(url);
|
|
57
|
+
const baseURL = parsedUrl.origin;
|
|
58
|
+
// Create a new transport for this base url if needed
|
|
59
|
+
let peerToUse;
|
|
60
|
+
if (!this.peers[baseURL]) {
|
|
61
|
+
// Create a peer for the request
|
|
62
|
+
const newTransport = new SimplifiedFetchTransport(baseURL);
|
|
63
|
+
peerToUse = {
|
|
64
|
+
peer: new Peer(this.wallet, newTransport, this.requestedCertificates, this.sessionManager)
|
|
65
|
+
};
|
|
66
|
+
this.peers[baseURL] = peerToUse;
|
|
67
|
+
const callbackId = this.peers[baseURL].peer.listenForCertificatesReceived((senderPublicKey, certs) => {
|
|
68
|
+
this.certificatesReceived.push(...certs);
|
|
69
|
+
// peerToUse.peer.stopListeningForCertificatesReceived()
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
// Check if there's a session associated with this baseURL
|
|
74
|
+
if (this.peers[baseURL].supportsMutualAuth === false) {
|
|
75
|
+
// Use standard fetch if mutual authentication is not supported
|
|
76
|
+
try {
|
|
77
|
+
const response = await this.handleFetchAndValidate(url, config, this.peers[baseURL]);
|
|
78
|
+
resolve(response);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
reject(error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
peerToUse = this.peers[baseURL];
|
|
85
|
+
}
|
|
86
|
+
// Serialize the simplified fetch request.
|
|
87
|
+
const requestNonce = Random(32);
|
|
88
|
+
const requestNonceAsBase64 = Utils.toBase64(requestNonce);
|
|
89
|
+
const writer = await this.serializeRequest(method, headers, body, parsedUrl, requestNonce);
|
|
90
|
+
// Setup general message listener to resolve requests once a response is received
|
|
91
|
+
this.callbacks[requestNonceAsBase64] = { resolve, reject };
|
|
92
|
+
const listenerId = peerToUse.peer.listenForGeneralMessages((senderPublicKey, payload) => {
|
|
93
|
+
// Create a reader
|
|
94
|
+
const responseReader = new Utils.Reader(payload);
|
|
95
|
+
// Deserialize first 32 bytes of payload
|
|
96
|
+
const responseNonceAsBase64 = Utils.toBase64(responseReader.read(32));
|
|
97
|
+
if (responseNonceAsBase64 === requestNonceAsBase64) {
|
|
98
|
+
peerToUse.peer.stopListeningForGeneralMessages(listenerId);
|
|
99
|
+
// Save the identity key for the peer for future requests, since we have it here.
|
|
100
|
+
this.peers[baseURL].identityKey = senderPublicKey;
|
|
101
|
+
this.peers[baseURL].supportsMutualAuth = true;
|
|
102
|
+
// Status code
|
|
103
|
+
const statusCode = responseReader.readVarIntNum();
|
|
104
|
+
// Headers
|
|
105
|
+
const responseHeaders = {};
|
|
106
|
+
const nHeaders = responseReader.readVarIntNum();
|
|
107
|
+
if (nHeaders > 0) {
|
|
108
|
+
for (let i = 0; i < nHeaders; i++) {
|
|
109
|
+
const nHeaderKeyBytes = responseReader.readVarIntNum();
|
|
110
|
+
const headerKeyBytes = responseReader.read(nHeaderKeyBytes);
|
|
111
|
+
const headerKey = Utils.toUTF8(headerKeyBytes);
|
|
112
|
+
const nHeaderValueBytes = responseReader.readVarIntNum();
|
|
113
|
+
const headerValueBytes = responseReader.read(nHeaderValueBytes);
|
|
114
|
+
const headerValue = Utils.toUTF8(headerValueBytes);
|
|
115
|
+
responseHeaders[headerKey] = headerValue;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// Add back the server identity key header
|
|
119
|
+
responseHeaders['x-bsv-auth-identity-key'] = senderPublicKey;
|
|
120
|
+
// Body
|
|
121
|
+
let responseBody;
|
|
122
|
+
const responseBodyBytes = responseReader.readVarIntNum();
|
|
123
|
+
if (responseBodyBytes > 0) {
|
|
124
|
+
responseBody = responseReader.read(responseBodyBytes);
|
|
125
|
+
}
|
|
126
|
+
// Create the Response object
|
|
127
|
+
const responseValue = new Response(responseBody ? new Uint8Array(responseBody) : null, {
|
|
128
|
+
status: statusCode,
|
|
129
|
+
statusText: `${statusCode}`,
|
|
130
|
+
headers: new Headers(responseHeaders)
|
|
131
|
+
});
|
|
132
|
+
// Resolve or reject the correct request with the response data
|
|
133
|
+
this.callbacks[requestNonceAsBase64].resolve(responseValue);
|
|
134
|
+
// Clean up
|
|
135
|
+
delete this.callbacks[requestNonceAsBase64];
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
// Send the request, now that all listeners are set up
|
|
139
|
+
await peerToUse.peer.toPeer(writer.toArray(), peerToUse.identityKey).catch(async (error) => {
|
|
140
|
+
if (error.message.includes('HTTP server failed to authenticate')) {
|
|
141
|
+
try {
|
|
142
|
+
const response = await this.handleFetchAndValidate(url, config, peerToUse);
|
|
143
|
+
resolve(response);
|
|
144
|
+
}
|
|
145
|
+
catch (fetchError) {
|
|
146
|
+
reject(fetchError);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
reject(error);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
catch (e) {
|
|
155
|
+
reject(e);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
// Check if server requires payment to access the requested route
|
|
159
|
+
if (response.status === 402) {
|
|
160
|
+
// Create and attach a payment, then retry
|
|
161
|
+
return await this.handlePaymentAndRetry(url, config, response);
|
|
162
|
+
}
|
|
163
|
+
return response;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Request Certificates from a Peer
|
|
167
|
+
* @param baseUrl
|
|
168
|
+
* @param certificatesToRequest
|
|
169
|
+
*/
|
|
170
|
+
async sendCertificateRequest(baseUrl, certificatesToRequest) {
|
|
171
|
+
const parsedUrl = new URL(baseUrl);
|
|
172
|
+
const baseURL = parsedUrl.origin;
|
|
173
|
+
let peerToUse;
|
|
174
|
+
if (this.peers[baseURL]) {
|
|
175
|
+
peerToUse = { peer: this.peers[baseURL].peer };
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
const newTransport = new SimplifiedFetchTransport(baseURL);
|
|
179
|
+
peerToUse = {
|
|
180
|
+
peer: new Peer(this.wallet, newTransport, this.requestedCertificates, this.sessionManager)
|
|
181
|
+
};
|
|
182
|
+
this.peers[baseURL] = peerToUse;
|
|
183
|
+
}
|
|
184
|
+
// Return a promise that resolves when certificates are received
|
|
185
|
+
return new Promise(async (resolve, reject) => {
|
|
186
|
+
// Set up the listener before making the request
|
|
187
|
+
const callbackId = peerToUse.peer.listenForCertificatesReceived((_senderPublicKey, certs) => {
|
|
188
|
+
peerToUse.peer.stopListeningForCertificatesReceived(callbackId);
|
|
189
|
+
this.certificatesReceived.push(...certs);
|
|
190
|
+
resolve(certs);
|
|
191
|
+
});
|
|
192
|
+
try {
|
|
193
|
+
// Initiate the certificate request
|
|
194
|
+
await peerToUse.peer.requestCertificates(certificatesToRequest, peerToUse.identityKey);
|
|
195
|
+
}
|
|
196
|
+
catch (err) {
|
|
197
|
+
peerToUse.peer.stopListeningForCertificatesReceived(callbackId);
|
|
198
|
+
reject(err);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Return any certificates we've collected thus far, then clear them out.
|
|
204
|
+
*/
|
|
205
|
+
consumeReceivedCertificates() {
|
|
206
|
+
return this.certificatesReceived.splice(0);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Serializes the HTTP request to be sent over the Transport.
|
|
210
|
+
*
|
|
211
|
+
* @param method - The HTTP method (e.g., 'GET', 'POST') for the request.
|
|
212
|
+
* @param headers - A record of HTTP headers to include in the request.
|
|
213
|
+
* @param body - The body of the request, if applicable (e.g., for POST/PUT requests).
|
|
214
|
+
* @param parsedUrl - The parsed URL object containing the full request URL.
|
|
215
|
+
* @param requestNonce - A unique random nonce to ensure request integrity.
|
|
216
|
+
* @returns A promise that resolves to a `Writer` containing the serialized request.
|
|
217
|
+
*
|
|
218
|
+
* @throws Will throw an error if unsupported headers are used or serialization fails.
|
|
219
|
+
*/
|
|
220
|
+
async serializeRequest(method, headers, body, parsedUrl, requestNonce) {
|
|
221
|
+
const writer = new Utils.Writer();
|
|
222
|
+
// Write request nonce
|
|
223
|
+
writer.write(requestNonce);
|
|
224
|
+
// Method length
|
|
225
|
+
writer.writeVarIntNum(method.length);
|
|
226
|
+
// Method
|
|
227
|
+
writer.write(Utils.toArray(method));
|
|
228
|
+
// Handle pathname (e.g. /path/to/resource)
|
|
229
|
+
if (parsedUrl.pathname.length > 0) {
|
|
230
|
+
// Pathname length
|
|
231
|
+
const pathnameAsArray = Utils.toArray(parsedUrl.pathname);
|
|
232
|
+
writer.writeVarIntNum(pathnameAsArray.length);
|
|
233
|
+
// Pathname
|
|
234
|
+
writer.write(pathnameAsArray);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
writer.writeVarIntNum(-1);
|
|
238
|
+
}
|
|
239
|
+
// Handle search params (e.g. ?q=hello)
|
|
240
|
+
if (parsedUrl.search.length > 0) {
|
|
241
|
+
// search length
|
|
242
|
+
const searchAsArray = Utils.toArray(parsedUrl.search);
|
|
243
|
+
writer.writeVarIntNum(searchAsArray.length);
|
|
244
|
+
// search
|
|
245
|
+
writer.write(searchAsArray);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
writer.writeVarIntNum(-1);
|
|
249
|
+
}
|
|
250
|
+
// Construct headers to send / sign:
|
|
251
|
+
// - Custom headers prefixed with x-bsv are included
|
|
252
|
+
// - x-bsv-auth headers are not allowed
|
|
253
|
+
// - content-type and authorization are signed by client
|
|
254
|
+
const includedHeaders = [];
|
|
255
|
+
for (let [k, v] of Object.entries(headers)) {
|
|
256
|
+
k = k.toLowerCase(); // We will always sign lower-case header keys
|
|
257
|
+
if (k.startsWith('x-bsv-') || k === 'content-type' || k === 'authorization') {
|
|
258
|
+
if (k.startsWith('x-bsv-auth')) {
|
|
259
|
+
throw new Error('No BSV auth headers allowed here!');
|
|
260
|
+
}
|
|
261
|
+
includedHeaders.push([k, v]);
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
throw new Error('Unsupported header in the simplified fetch implementation. Only content-type, authorization, and x-bsv-* headers are supported.');
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
// nHeaders
|
|
268
|
+
writer.writeVarIntNum(includedHeaders.length);
|
|
269
|
+
for (let i = 0; i < includedHeaders.length; i++) {
|
|
270
|
+
// headerKeyLength
|
|
271
|
+
const headerKeyAsArray = Utils.toArray(includedHeaders[i][0], 'utf8');
|
|
272
|
+
writer.writeVarIntNum(headerKeyAsArray.length);
|
|
273
|
+
// headerKey
|
|
274
|
+
writer.write(headerKeyAsArray);
|
|
275
|
+
// headerValueLength
|
|
276
|
+
const headerValueAsArray = Utils.toArray(includedHeaders[i][1], 'utf8');
|
|
277
|
+
writer.writeVarIntNum(headerValueAsArray.length);
|
|
278
|
+
// headerValue
|
|
279
|
+
writer.write(headerValueAsArray);
|
|
280
|
+
}
|
|
281
|
+
// Handle body
|
|
282
|
+
if (body) {
|
|
283
|
+
const reqBody = await this.normalizeBodyToNumberArray(body); // Use the utility function
|
|
284
|
+
writer.writeVarIntNum(reqBody.length);
|
|
285
|
+
writer.write(reqBody);
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
writer.writeVarIntNum(-1); // No body
|
|
289
|
+
}
|
|
290
|
+
return writer;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Handles a non-authenticated fetch requests and validates that the server is not claiming to be authenticated.
|
|
294
|
+
*/
|
|
295
|
+
async handleFetchAndValidate(url, config, peerToUse) {
|
|
296
|
+
const response = await fetch(url, config);
|
|
297
|
+
response.headers.forEach(header => {
|
|
298
|
+
if (header.toLocaleLowerCase().startsWith('x-bsv')) {
|
|
299
|
+
throw new Error('The server is trying to claim it has been authenticated when it has not!');
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
if (response.ok) {
|
|
303
|
+
peerToUse.supportsMutualAuth = false;
|
|
304
|
+
return response;
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
throw new Error(`Request failed with status: ${response.status}`);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* If we get 402 Payment Required, we build a transaction via wallet.createAction()
|
|
312
|
+
* and re-attempt the request with an x-bsv-payment header.
|
|
313
|
+
*/
|
|
314
|
+
async handlePaymentAndRetry(url, config = {}, originalResponse) {
|
|
315
|
+
// Make sure the server is using the correct payment version
|
|
316
|
+
const paymentVersion = originalResponse.headers.get('x-bsv-payment-version');
|
|
317
|
+
if (!paymentVersion || paymentVersion !== PAYMENT_VERSION) {
|
|
318
|
+
throw new Error(`Unsupported x-bsv-payment-version response header. Client version: ${PAYMENT_VERSION}, Server version: ${paymentVersion}`);
|
|
319
|
+
}
|
|
320
|
+
// Get required headers from the 402 response
|
|
321
|
+
const satoshisRequiredHeader = originalResponse.headers.get('x-bsv-payment-satoshis-required');
|
|
322
|
+
if (!satoshisRequiredHeader) {
|
|
323
|
+
throw new Error('Missing x-bsv-payment-satoshis-required response header.');
|
|
324
|
+
}
|
|
325
|
+
const satoshisRequired = parseInt(satoshisRequiredHeader);
|
|
326
|
+
if (isNaN(satoshisRequired) || satoshisRequired <= 0) {
|
|
327
|
+
throw new Error('Invalid x-bsv-payment-satoshis-required response header value.');
|
|
328
|
+
}
|
|
329
|
+
const serverIdentityKey = originalResponse.headers.get('x-bsv-auth-identity-key');
|
|
330
|
+
if (!serverIdentityKey) {
|
|
331
|
+
throw new Error('Missing x-bsv-auth-identity-key response header.');
|
|
332
|
+
}
|
|
333
|
+
const derivationPrefix = originalResponse.headers.get('x-bsv-payment-derivation-prefix');
|
|
334
|
+
if (!derivationPrefix) {
|
|
335
|
+
throw new Error('Missing x-bsv-payment-derivation-prefix response header.');
|
|
336
|
+
}
|
|
337
|
+
// Create a random suffix for the derivation path
|
|
338
|
+
const derivationSuffix = Utils.toBase64(Random(10));
|
|
339
|
+
// Derive the script hex from the server identity key
|
|
340
|
+
const { publicKey: derivedPublicKey } = await this.wallet.getPublicKey({
|
|
341
|
+
protocolID: [2, 'wallet payment'],
|
|
342
|
+
keyID: `${derivationPrefix} ${derivationSuffix}`,
|
|
343
|
+
counterparty: serverIdentityKey
|
|
344
|
+
});
|
|
345
|
+
const lockingScript = new P2PKH().lock(PublicKey.fromString(derivedPublicKey).toHash()).toHex();
|
|
346
|
+
// Create the payment transaction using createAction
|
|
347
|
+
const { tx } = await this.wallet.createAction({
|
|
348
|
+
description: `Payment for request to ${new URL(url).origin}`,
|
|
349
|
+
outputs: [{
|
|
350
|
+
satoshis: satoshisRequired,
|
|
351
|
+
lockingScript,
|
|
352
|
+
outputDescription: 'HTTP request payment'
|
|
353
|
+
}]
|
|
354
|
+
});
|
|
355
|
+
// Attach the payment to the request headers
|
|
356
|
+
config.headers = config.headers || {};
|
|
357
|
+
config.headers['x-bsv-payment'] = JSON.stringify({
|
|
358
|
+
derivationPrefix,
|
|
359
|
+
transaction: Utils.toBase64(tx)
|
|
360
|
+
});
|
|
361
|
+
config.retryCounter ??= 3;
|
|
362
|
+
// Re-attempt request with payment attached
|
|
363
|
+
return this.fetch(url, config);
|
|
364
|
+
}
|
|
365
|
+
async normalizeBodyToNumberArray(body) {
|
|
366
|
+
// 1. Null / undefined
|
|
367
|
+
if (body == null) {
|
|
368
|
+
return [];
|
|
369
|
+
}
|
|
370
|
+
// 2. number[]
|
|
371
|
+
if (Array.isArray(body) && body.every((item) => typeof item === 'number')) {
|
|
372
|
+
return body; // Return the array as is
|
|
373
|
+
}
|
|
374
|
+
// 3. string
|
|
375
|
+
if (typeof body === 'string') {
|
|
376
|
+
return Utils.toArray(body, 'utf8');
|
|
377
|
+
}
|
|
378
|
+
// 4. ArrayBuffer / TypedArrays
|
|
379
|
+
if (body instanceof ArrayBuffer || ArrayBuffer.isView(body)) {
|
|
380
|
+
const typedArray = body instanceof ArrayBuffer ? new Uint8Array(body) : new Uint8Array(body.buffer);
|
|
381
|
+
return Array.from(typedArray);
|
|
382
|
+
}
|
|
383
|
+
// 5. Blob
|
|
384
|
+
if (body instanceof Blob) {
|
|
385
|
+
const arrayBuffer = await body.arrayBuffer();
|
|
386
|
+
return Array.from(new Uint8Array(arrayBuffer));
|
|
387
|
+
}
|
|
388
|
+
// 6. FormData
|
|
389
|
+
if (body instanceof FormData) {
|
|
390
|
+
const entries = [];
|
|
391
|
+
body.forEach((value, key) => {
|
|
392
|
+
entries.push([key, value.toString()]);
|
|
393
|
+
});
|
|
394
|
+
const urlEncoded = new URLSearchParams(entries).toString();
|
|
395
|
+
return Utils.toArray(urlEncoded, 'utf8');
|
|
396
|
+
}
|
|
397
|
+
// 7. URLSearchParams
|
|
398
|
+
if (body instanceof URLSearchParams) {
|
|
399
|
+
return Utils.toArray(body.toString(), 'utf8');
|
|
400
|
+
}
|
|
401
|
+
// 8. ReadableStream
|
|
402
|
+
if (body instanceof ReadableStream) {
|
|
403
|
+
throw new Error('ReadableStream cannot be directly converted to number[].');
|
|
404
|
+
}
|
|
405
|
+
// 9. Fallback
|
|
406
|
+
throw new Error('Unsupported body type in this SimplifiedFetch implementation.');
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
//# sourceMappingURL=AuthFetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthFetch.js","sourceRoot":"","sources":["../../../../../src/auth/clients/AuthFetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAU,MAAM,iBAAiB,CAAA;AACzE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAA;AACpF,OAAO,EAAE,cA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,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAA;IAClF,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/auth/clients/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './certificates/index.js';
|
|
2
|
+
export * from './Peer.js';
|
|
3
|
+
export * from './SessionManager.js';
|
|
4
|
+
export * from './types.js';
|
|
5
|
+
export * from './utils/index.js';
|
|
6
|
+
export * from './clients/index.js';
|
|
7
|
+
export * from './transports/index.js';
|
|
2
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/auth/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/auth/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA;AACvC,cAAc,WAAW,CAAA;AACzB,cAAc,qBAAqB,CAAA;AACnC,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAChC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA"}
|