@bsv/sdk 1.3.35 → 1.4.0
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/mod.js +1 -0
- package/dist/cjs/mod.js.map +1 -1
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/auth/Peer.js +42 -14
- package/dist/cjs/src/auth/Peer.js.map +1 -1
- package/dist/cjs/src/auth/certificates/Certificate.js +50 -22
- package/dist/cjs/src/auth/certificates/Certificate.js.map +1 -1
- package/dist/cjs/src/auth/certificates/MasterCertificate.js +35 -10
- package/dist/cjs/src/auth/certificates/MasterCertificate.js.map +1 -1
- package/dist/cjs/src/auth/certificates/VerifiableCertificate.js +28 -4
- package/dist/cjs/src/auth/certificates/VerifiableCertificate.js.map +1 -1
- package/dist/cjs/src/auth/certificates/__tests/CompletedProtoWallet.js +5 -2
- package/dist/cjs/src/auth/certificates/__tests/CompletedProtoWallet.js.map +1 -1
- package/dist/cjs/src/auth/clients/AuthFetch.js +83 -27
- package/dist/cjs/src/auth/clients/AuthFetch.js.map +1 -1
- package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js +70 -34
- package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
- package/dist/cjs/src/auth/utils/createNonce.js +31 -4
- package/dist/cjs/src/auth/utils/createNonce.js.map +1 -1
- package/dist/cjs/src/auth/utils/verifyNonce.js +26 -3
- package/dist/cjs/src/auth/utils/verifyNonce.js.map +1 -1
- package/dist/cjs/src/overlay-tools/LookupResolver.js +2 -2
- package/dist/cjs/src/overlay-tools/LookupResolver.js.map +1 -1
- package/dist/cjs/src/primitives/utils.js.map +1 -1
- package/dist/cjs/src/storage/StorageUploader.js +93 -0
- package/dist/cjs/src/storage/StorageUploader.js.map +1 -0
- package/dist/cjs/src/storage/StorageUtils.js +73 -0
- package/dist/cjs/src/storage/StorageUtils.js.map +1 -0
- package/dist/cjs/src/storage/__test/StorageUploader.test.js +92 -0
- package/dist/cjs/src/storage/__test/StorageUploader.test.js.map +1 -0
- package/dist/cjs/src/storage/__test/StorageUtils.test.js +97 -0
- package/dist/cjs/src/storage/__test/StorageUtils.test.js.map +1 -0
- package/dist/cjs/src/storage/index.js +30 -0
- package/dist/cjs/src/storage/index.js.map +1 -0
- package/dist/cjs/src/wallet/WalletClient.js +4 -4
- package/dist/cjs/src/wallet/WalletClient.js.map +1 -1
- package/dist/cjs/src/wallet/substrates/HTTPWalletWire.js +26 -3
- package/dist/cjs/src/wallet/substrates/HTTPWalletWire.js.map +1 -1
- package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js +178 -155
- package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
- package/dist/cjs/src/wallet/substrates/WalletWireTransceiver.js +171 -148
- package/dist/cjs/src/wallet/substrates/WalletWireTransceiver.js.map +1 -1
- package/dist/cjs/src/wallet/substrates/XDM.js +29 -2
- package/dist/cjs/src/wallet/substrates/XDM.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/mod.js +1 -0
- package/dist/esm/mod.js.map +1 -1
- package/dist/esm/src/auth/Peer.js +7 -5
- package/dist/esm/src/auth/Peer.js.map +1 -1
- package/dist/esm/src/auth/certificates/Certificate.js +3 -1
- package/dist/esm/src/auth/certificates/Certificate.js.map +1 -1
- package/dist/esm/src/auth/certificates/MasterCertificate.js +3 -1
- package/dist/esm/src/auth/certificates/MasterCertificate.js.map +1 -1
- package/dist/esm/src/auth/certificates/VerifiableCertificate.js +2 -1
- package/dist/esm/src/auth/certificates/VerifiableCertificate.js.map +1 -1
- package/dist/esm/src/auth/certificates/__tests/CompletedProtoWallet.js +1 -1
- package/dist/esm/src/auth/certificates/__tests/CompletedProtoWallet.js.map +1 -1
- package/dist/esm/src/auth/clients/AuthFetch.js +38 -8
- package/dist/esm/src/auth/clients/AuthFetch.js.map +1 -1
- package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js +31 -18
- package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
- package/dist/esm/src/auth/utils/createNonce.js +2 -1
- package/dist/esm/src/auth/utils/createNonce.js.map +1 -1
- package/dist/esm/src/auth/utils/verifyNonce.js +1 -1
- package/dist/esm/src/auth/utils/verifyNonce.js.map +1 -1
- package/dist/esm/src/overlay-tools/LookupResolver.js +2 -2
- package/dist/esm/src/overlay-tools/LookupResolver.js.map +1 -1
- package/dist/esm/src/primitives/utils.js.map +1 -1
- package/dist/esm/src/storage/StorageUploader.js +68 -0
- package/dist/esm/src/storage/StorageUploader.js.map +1 -0
- package/dist/esm/src/storage/StorageUtils.js +65 -0
- package/dist/esm/src/storage/StorageUtils.js.map +1 -0
- package/dist/esm/src/storage/__test/StorageUploader.test.js +64 -0
- package/dist/esm/src/storage/__test/StorageUploader.test.js.map +1 -0
- package/dist/esm/src/storage/__test/StorageUtils.test.js +72 -0
- package/dist/esm/src/storage/__test/StorageUtils.test.js.map +1 -0
- package/dist/esm/src/storage/index.js +3 -0
- package/dist/esm/src/storage/index.js.map +1 -0
- package/dist/esm/src/wallet/WalletClient.js +4 -4
- package/dist/esm/src/wallet/WalletClient.js.map +1 -1
- package/dist/esm/src/wallet/substrates/HTTPWalletWire.js +1 -1
- package/dist/esm/src/wallet/substrates/HTTPWalletWire.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 +2 -2
- package/dist/esm/src/wallet/substrates/WalletWireTransceiver.js.map +1 -1
- package/dist/esm/src/wallet/substrates/XDM.js +2 -1
- package/dist/esm/src/wallet/substrates/XDM.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/mod.d.ts +1 -0
- package/dist/types/mod.d.ts.map +1 -1
- package/dist/types/src/auth/Peer.d.ts +1 -1
- package/dist/types/src/auth/Peer.d.ts.map +1 -1
- package/dist/types/src/auth/certificates/Certificate.d.ts +2 -1
- package/dist/types/src/auth/certificates/Certificate.d.ts.map +1 -1
- package/dist/types/src/auth/certificates/MasterCertificate.d.ts +2 -1
- package/dist/types/src/auth/certificates/MasterCertificate.d.ts.map +1 -1
- package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts +2 -1
- package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts.map +1 -1
- package/dist/types/src/auth/certificates/__tests/CompletedProtoWallet.d.ts +1 -1
- package/dist/types/src/auth/certificates/__tests/CompletedProtoWallet.d.ts.map +1 -1
- package/dist/types/src/auth/clients/AuthFetch.d.ts +10 -9
- package/dist/types/src/auth/clients/AuthFetch.d.ts.map +1 -1
- package/dist/types/src/auth/transports/SimplifiedFetchTransport.d.ts.map +1 -1
- package/dist/types/src/auth/utils/createNonce.d.ts +1 -1
- package/dist/types/src/auth/utils/createNonce.d.ts.map +1 -1
- package/dist/types/src/auth/utils/getVerifiableCertificates.d.ts +1 -1
- package/dist/types/src/auth/utils/getVerifiableCertificates.d.ts.map +1 -1
- package/dist/types/src/auth/utils/verifyNonce.d.ts +1 -1
- package/dist/types/src/auth/utils/verifyNonce.d.ts.map +1 -1
- package/dist/types/src/primitives/utils.d.ts +4 -1
- package/dist/types/src/primitives/utils.d.ts.map +1 -1
- package/dist/types/src/storage/StorageUploader.d.ts +40 -0
- package/dist/types/src/storage/StorageUploader.d.ts.map +1 -0
- package/dist/types/src/storage/StorageUtils.d.ts +31 -0
- package/dist/types/src/storage/StorageUtils.d.ts.map +1 -0
- package/dist/types/src/storage/__test/StorageUploader.test.d.ts +2 -0
- package/dist/types/src/storage/__test/StorageUploader.test.d.ts.map +1 -0
- package/dist/types/src/storage/__test/StorageUtils.test.d.ts +2 -0
- package/dist/types/src/storage/__test/StorageUtils.test.d.ts.map +1 -0
- package/dist/types/src/storage/index.d.ts +3 -0
- package/dist/types/src/storage/index.d.ts.map +1 -0
- package/dist/types/src/wallet/substrates/XDM.d.ts +1 -1
- package/dist/types/src/wallet/substrates/XDM.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/docs/primitives.md +4 -1
- package/docs/storage.md +210 -0
- package/docs/wallet-substrates.md +0 -225
- package/mod.ts +1 -0
- package/package.json +12 -2
- package/src/auth/Peer.ts +8 -5
- package/src/auth/__tests/Peer.test.ts +43 -48
- package/src/auth/certificates/Certificate.ts +5 -5
- package/src/auth/certificates/MasterCertificate.ts +5 -5
- package/src/auth/certificates/VerifiableCertificate.ts +6 -6
- package/src/auth/certificates/__tests/CompletedProtoWallet.ts +1 -15
- package/src/auth/clients/AuthFetch.ts +59 -18
- package/src/auth/transports/SimplifiedFetchTransport.ts +31 -19
- package/src/auth/utils/__tests/cryptononce.test.ts +0 -2
- package/src/auth/utils/createNonce.ts +3 -3
- package/src/auth/utils/getVerifiableCertificates.ts +1 -1
- package/src/auth/utils/verifyNonce.ts +2 -1
- package/src/overlay-tools/LookupResolver.ts +2 -2
- package/src/primitives/utils.ts +1 -1
- package/src/storage/StorageUploader.ts +108 -0
- package/src/storage/StorageUtils.ts +66 -0
- package/src/storage/__test/StorageUploader.test.ts +80 -0
- package/src/storage/__test/StorageUtils.test.ts +86 -0
- package/src/storage/index.ts +2 -0
- package/src/transaction/__tests/Transaction.benchmarks.test.ts +1 -16
- package/src/wallet/WalletClient.ts +4 -4
- package/src/wallet/substrates/HTTPWalletWire.ts +1 -1
- package/src/wallet/substrates/WalletWireProcessor.ts +1 -1
- package/src/wallet/substrates/WalletWireTransceiver.ts +2 -2
- package/src/wallet/substrates/XDM.ts +3 -2
|
@@ -6,7 +6,7 @@ import { Utils, PrivateKey } from '../../primitives/index.js'
|
|
|
6
6
|
import { VerifiableCertificate } from '../../auth/certificates/VerifiableCertificate.js'
|
|
7
7
|
import { MasterCertificate } from '../../auth/certificates/MasterCertificate.js'
|
|
8
8
|
import { getVerifiableCertificates } from '../../auth/utils/getVerifiableCertificates.js'
|
|
9
|
-
import { CompletedProtoWallet } from '
|
|
9
|
+
import { CompletedProtoWallet } from '../certificates/__tests/CompletedProtoWallet.js'
|
|
10
10
|
|
|
11
11
|
jest.mock('../../auth/utils/getVerifiableCertificates')
|
|
12
12
|
|
|
@@ -211,15 +211,13 @@ describe('Peer class mutual authentication and certificate exchange', () => {
|
|
|
211
211
|
const bobReceivedGeneralMessage = new Promise<void>((resolve) => {
|
|
212
212
|
bob.listenForGeneralMessages((senderPublicKey, payload) => {
|
|
213
213
|
(async () => {
|
|
214
|
-
console.log('Bob received message:', Utils.toUTF8(payload))
|
|
215
214
|
await bob.toPeer(Utils.toArray('Hello Alice!'), senderPublicKey)
|
|
216
215
|
resolve()
|
|
217
|
-
})().catch(e =>
|
|
216
|
+
})().catch(e => { })
|
|
218
217
|
})
|
|
219
218
|
})
|
|
220
219
|
const aliceReceivedGeneralMessage = new Promise<void>((resolve) => {
|
|
221
220
|
alice.listenForGeneralMessages((senderPublicKey, payload) => {
|
|
222
|
-
console.log('Alice received message:', Utils.toUTF8(payload))
|
|
223
221
|
resolve()
|
|
224
222
|
})
|
|
225
223
|
})
|
|
@@ -260,29 +258,26 @@ describe('Peer class mutual authentication and certificate exchange', () => {
|
|
|
260
258
|
const bobReceivedGeneralMessage = new Promise<void>((resolve) => {
|
|
261
259
|
bob.listenForGeneralMessages((senderPublicKey, payload) => {
|
|
262
260
|
(async () => {
|
|
263
|
-
console.log('Bob 1 received message:', Utils.toUTF8(payload))
|
|
264
261
|
await bob.toPeer(Utils.toArray('Hello Alice!'), senderPublicKey)
|
|
265
262
|
resolve()
|
|
266
263
|
bobMessageHandler(senderPublicKey, payload)
|
|
267
|
-
})().catch(e =>
|
|
264
|
+
})().catch(e => { })
|
|
268
265
|
})
|
|
269
266
|
})
|
|
270
267
|
let aliceReceivedGeneralMessageOnFirstDevice = new Promise<void>((resolve) => {
|
|
271
268
|
aliceFirstDevice.listenForGeneralMessages((senderPublicKey, payload) => {
|
|
272
269
|
(async () => {
|
|
273
|
-
console.log('Alice 1 received message:', Utils.toUTF8(payload))
|
|
274
270
|
resolve()
|
|
275
271
|
alice1MessageHandler(senderPublicKey, payload)
|
|
276
|
-
})().catch(e =>
|
|
272
|
+
})().catch(e => { })
|
|
277
273
|
})
|
|
278
274
|
})
|
|
279
275
|
const aliceReceivedGeneralMessageOnOtherDevice = new Promise<void>((resolve) => {
|
|
280
276
|
aliceOtherDevice.listenForGeneralMessages((senderPublicKey, payload) => {
|
|
281
277
|
(async () => {
|
|
282
|
-
console.log('Alice 2 received message:', Utils.toUTF8(payload))
|
|
283
278
|
resolve()
|
|
284
279
|
alice2MessageHandler(senderPublicKey, payload)
|
|
285
|
-
})().catch(e =>
|
|
280
|
+
})().catch(e => { })
|
|
286
281
|
})
|
|
287
282
|
})
|
|
288
283
|
|
|
@@ -333,16 +328,16 @@ describe('Peer class mutual authentication and certificate exchange', () => {
|
|
|
333
328
|
// Use a for...of loop instead of forEach with an async callback.
|
|
334
329
|
for (const cert of certificatesReceivedByBob) {
|
|
335
330
|
// Decrypt to ensure it has the correct fields.
|
|
336
|
-
const decryptedFields = await cert.decryptFields(walletB)
|
|
331
|
+
// const decryptedFields = await cert.decryptFields(walletB)
|
|
337
332
|
if (cert.certifier !== 'bob') {
|
|
338
|
-
console.log('Bob accepted the message:', Utils.toUTF8(payload))
|
|
339
|
-
console.log('Decrypted fields:', decryptedFields)
|
|
333
|
+
// console.log('Bob accepted the message:', Utils.toUTF8(payload))
|
|
334
|
+
// console.log('Decrypted fields:', decryptedFields)
|
|
340
335
|
}
|
|
341
336
|
}
|
|
342
337
|
}
|
|
343
338
|
resolve()
|
|
344
339
|
})().catch((e) => {
|
|
345
|
-
console.error(e)
|
|
340
|
+
// console.error(e)
|
|
346
341
|
})
|
|
347
342
|
})
|
|
348
343
|
})
|
|
@@ -401,9 +396,9 @@ describe('Peer class mutual authentication and certificate exchange', () => {
|
|
|
401
396
|
Object.keys(decryptedFields).length !== 0 &&
|
|
402
397
|
typeof decryptedFields.libraryCardNumber !== 'undefined'
|
|
403
398
|
) {
|
|
404
|
-
console.log(
|
|
405
|
-
|
|
406
|
-
)
|
|
399
|
+
// console.log(
|
|
400
|
+
// `Alice received Bob's library card number: ${decryptedFields.libraryCardNumber}`
|
|
401
|
+
// )
|
|
407
402
|
aliceAcceptedLibraryCard()
|
|
408
403
|
}
|
|
409
404
|
}
|
|
@@ -412,7 +407,7 @@ describe('Peer class mutual authentication and certificate exchange', () => {
|
|
|
412
407
|
|
|
413
408
|
const bobReceivedGeneralMessage = new Promise<void>((resolve) => {
|
|
414
409
|
bob.listenForGeneralMessages((senderPublicKey, payload) => {
|
|
415
|
-
console.log('Bob received message from Alice:', Utils.toUTF8(payload))
|
|
410
|
+
// console.log('Bob received message from Alice:', Utils.toUTF8(payload))
|
|
416
411
|
resolve()
|
|
417
412
|
})
|
|
418
413
|
})
|
|
@@ -457,7 +452,7 @@ describe('Peer class mutual authentication and certificate exchange', () => {
|
|
|
457
452
|
bob.listenForGeneralMessages((senderPublicKey, payload) => {
|
|
458
453
|
(async () => {
|
|
459
454
|
await bobReceivedCertificates
|
|
460
|
-
console.log('Bob received message:', Utils.toUTF8(payload))
|
|
455
|
+
// console.log('Bob received message:', Utils.toUTF8(payload))
|
|
461
456
|
|
|
462
457
|
// Bob requests additional certificates after initial communication
|
|
463
458
|
await bob.requestCertificates(certificatesToRequest, senderPublicKey)
|
|
@@ -478,11 +473,11 @@ describe('Peer class mutual authentication and certificate exchange', () => {
|
|
|
478
473
|
// Decrypt to confirm
|
|
479
474
|
for (const cert of certificates) {
|
|
480
475
|
const decrypted = await cert.decryptFields(walletB)
|
|
481
|
-
console.log(
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
)
|
|
485
|
-
console.log('Decrypted fields:', decrypted)
|
|
476
|
+
// console.log(
|
|
477
|
+
// 'Bob received additional certificates from Alice:',
|
|
478
|
+
// cert
|
|
479
|
+
// )
|
|
480
|
+
// console.log('Decrypted fields:', decrypted)
|
|
486
481
|
}
|
|
487
482
|
resolve()
|
|
488
483
|
}
|
|
@@ -540,9 +535,9 @@ describe('Peer class mutual authentication and certificate exchange', () => {
|
|
|
540
535
|
// Decrypt Alice's certificate fields
|
|
541
536
|
const decryptedFields = await cert.decryptFields(walletB)
|
|
542
537
|
if (typeof decryptedFields.membershipStatus !== 'undefined') {
|
|
543
|
-
console.log(
|
|
544
|
-
|
|
545
|
-
)
|
|
538
|
+
// console.log(
|
|
539
|
+
// `Bob received Alice's membership status: ${decryptedFields.membershipStatus}`
|
|
540
|
+
// )
|
|
546
541
|
bobAcceptedMembershipStatus()
|
|
547
542
|
resolve()
|
|
548
543
|
}
|
|
@@ -556,7 +551,7 @@ describe('Peer class mutual authentication and certificate exchange', () => {
|
|
|
556
551
|
|
|
557
552
|
const bobReceivedGeneralMessage = new Promise<void>((resolve) => {
|
|
558
553
|
bob.listenForGeneralMessages((senderPublicKey, payload) => {
|
|
559
|
-
console.log('Bob received message from Alice:', Utils.toUTF8(payload))
|
|
554
|
+
// console.log('Bob received message from Alice:', Utils.toUTF8(payload))
|
|
560
555
|
resolve()
|
|
561
556
|
})
|
|
562
557
|
})
|
|
@@ -633,14 +628,14 @@ describe('Peer class mutual authentication and certificate exchange', () => {
|
|
|
633
628
|
for (const cert of certificates) {
|
|
634
629
|
const decryptedFields = await cert.decryptFields(walletA)
|
|
635
630
|
if (decryptedFields.driversLicenseNumber !== undefined) {
|
|
636
|
-
console.log(
|
|
637
|
-
|
|
638
|
-
)
|
|
631
|
+
// console.log(
|
|
632
|
+
// `Alice received Bob's driver's license number: ${decryptedFields.driversLicenseNumber}`
|
|
633
|
+
// )
|
|
639
634
|
aliceAcceptedBobDL()
|
|
640
635
|
resolve()
|
|
641
636
|
}
|
|
642
637
|
}
|
|
643
|
-
})().catch(e =>
|
|
638
|
+
})().catch(e => { })
|
|
644
639
|
}
|
|
645
640
|
)
|
|
646
641
|
})
|
|
@@ -651,14 +646,14 @@ describe('Peer class mutual authentication and certificate exchange', () => {
|
|
|
651
646
|
for (const cert of certificates) {
|
|
652
647
|
const decryptedFields = await cert.decryptFields(walletB)
|
|
653
648
|
if (decryptedFields.driversLicenseNumber !== undefined) {
|
|
654
|
-
console.log(
|
|
655
|
-
|
|
656
|
-
)
|
|
649
|
+
// console.log(
|
|
650
|
+
// `Bob received Alice's driver's license number: ${decryptedFields.driversLicenseNumber}`
|
|
651
|
+
// )
|
|
657
652
|
bobAcceptedAliceDL()
|
|
658
653
|
resolve()
|
|
659
654
|
}
|
|
660
655
|
}
|
|
661
|
-
})().catch(e =>
|
|
656
|
+
})().catch(e => { })
|
|
662
657
|
}
|
|
663
658
|
)
|
|
664
659
|
})
|
|
@@ -666,19 +661,19 @@ describe('Peer class mutual authentication and certificate exchange', () => {
|
|
|
666
661
|
const bobReceivedGeneralMessage = new Promise<void>((resolve) => {
|
|
667
662
|
bob.listenForGeneralMessages((senderPublicKey, payload) => {
|
|
668
663
|
(async () => {
|
|
669
|
-
console.log('Bob received message from Alice:', Utils.toUTF8(payload))
|
|
664
|
+
// console.log('Bob received message from Alice:', Utils.toUTF8(payload))
|
|
670
665
|
await bob.toPeer(
|
|
671
666
|
Utils.toArray('Looking forward to carpooling!'),
|
|
672
667
|
senderPublicKey
|
|
673
668
|
)
|
|
674
669
|
resolve()
|
|
675
|
-
})().catch(e =>
|
|
670
|
+
})().catch(e => { })
|
|
676
671
|
})
|
|
677
672
|
})
|
|
678
673
|
|
|
679
674
|
const aliceReceivedGeneralMessage = new Promise<void>((resolve) => {
|
|
680
675
|
alice.listenForGeneralMessages((senderPublicKey, payload) => {
|
|
681
|
-
console.log('Alice received message from Bob:', Utils.toUTF8(payload))
|
|
676
|
+
// console.log('Alice received message from Bob:', Utils.toUTF8(payload))
|
|
682
677
|
resolve()
|
|
683
678
|
})
|
|
684
679
|
})
|
|
@@ -759,14 +754,14 @@ describe('Peer class mutual authentication and certificate exchange', () => {
|
|
|
759
754
|
for (const cert of certificates) {
|
|
760
755
|
const decryptedFields = await cert.decryptFields(walletA)
|
|
761
756
|
if (decryptedFields.email !== undefined || decryptedFields.name !== undefined) {
|
|
762
|
-
console.log(
|
|
763
|
-
|
|
764
|
-
)
|
|
757
|
+
// console.log(
|
|
758
|
+
// `Alice received Bob's certificate with fields: ${Object.keys(decryptedFields).join(', ')}`
|
|
759
|
+
// )
|
|
765
760
|
aliceAcceptedPartialCert()
|
|
766
761
|
resolve()
|
|
767
762
|
}
|
|
768
763
|
}
|
|
769
|
-
})().catch(e =>
|
|
764
|
+
})().catch(e => { })
|
|
770
765
|
})
|
|
771
766
|
})
|
|
772
767
|
|
|
@@ -776,20 +771,20 @@ describe('Peer class mutual authentication and certificate exchange', () => {
|
|
|
776
771
|
for (const cert of certificates) {
|
|
777
772
|
const decryptedFields = await cert.decryptFields(walletB)
|
|
778
773
|
if (decryptedFields.email !== undefined || decryptedFields.name !== undefined) {
|
|
779
|
-
console.log(
|
|
780
|
-
|
|
781
|
-
)
|
|
774
|
+
// console.log(
|
|
775
|
+
// `Bob received Alice's certificate with fields: ${Object.keys(decryptedFields).join(', ')}`
|
|
776
|
+
// )
|
|
782
777
|
bobAcceptedPartialCert()
|
|
783
778
|
resolve()
|
|
784
779
|
}
|
|
785
780
|
}
|
|
786
|
-
})().catch(e =>
|
|
781
|
+
})().catch(e => { })
|
|
787
782
|
})
|
|
788
783
|
})
|
|
789
784
|
|
|
790
785
|
const bobReceivedGeneralMessage = new Promise<void>((resolve) => {
|
|
791
786
|
bob.listenForGeneralMessages((senderPublicKey, payload) => {
|
|
792
|
-
console.log('Bob received message:', Utils.toUTF8(payload))
|
|
787
|
+
// console.log('Bob received message:', Utils.toUTF8(payload))
|
|
793
788
|
resolve()
|
|
794
789
|
})
|
|
795
790
|
})
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Utils,
|
|
3
2
|
Base64String,
|
|
4
3
|
PubKeyHex,
|
|
5
4
|
HexString,
|
|
6
5
|
OutpointString,
|
|
7
6
|
CertificateFieldNameUnder50Bytes,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
WalletProtocol
|
|
8
|
+
} from '../../wallet/Wallet.interfaces.js'
|
|
9
|
+
import * as Utils from '../../primitives/utils.js'
|
|
10
|
+
import ProtoWallet from '../../wallet/ProtoWallet.js'
|
|
11
|
+
import Signature from '../../primitives/Signature.js'
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Represents an Identity Certificate as per the Wallet interface specifications.
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
|
-
SymmetricKey,
|
|
3
|
-
Utils,
|
|
4
2
|
Base64String,
|
|
5
3
|
CertificateFieldNameUnder50Bytes,
|
|
6
4
|
HexString,
|
|
7
5
|
OutpointString,
|
|
8
6
|
PubKeyHex,
|
|
9
|
-
Random,
|
|
10
7
|
WalletCounterparty,
|
|
11
|
-
|
|
12
|
-
} from '../../../mod.js'
|
|
8
|
+
} from '../../wallet/Wallet.interfaces.js'
|
|
13
9
|
import Certificate from './Certificate.js'
|
|
10
|
+
import * as Utils from '../../primitives/utils.js'
|
|
11
|
+
import SymmetricKey from '../../primitives/SymmetricKey.js'
|
|
12
|
+
import Random from '../../primitives/Random.js'
|
|
13
|
+
import ProtoWallet from '../../wallet/ProtoWallet.js'
|
|
14
14
|
|
|
15
15
|
interface CreateCertificateFieldsResult {
|
|
16
16
|
certificateFields: Record<CertificateFieldNameUnder50Bytes, Base64String>
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
Utils,
|
|
1
|
+
import type {
|
|
2
|
+
PubKeyHex,
|
|
4
3
|
Base64String,
|
|
5
4
|
CertificateFieldNameUnder50Bytes,
|
|
6
5
|
HexString,
|
|
7
6
|
OutpointString,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
} from '../../wallet/Wallet.interfaces.js'
|
|
8
|
+
import SymmetricKey from '../../primitives/SymmetricKey.js'
|
|
9
|
+
import * as Utils from '../../primitives/utils.js'
|
|
10
|
+
import ProtoWallet from '../../wallet/ProtoWallet.js'
|
|
11
11
|
import Certificate from './Certificate.js'
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -1,35 +1,21 @@
|
|
|
1
1
|
//@ts-nocheck
|
|
2
|
-
import
|
|
2
|
+
import PrivateKey from '../../../primitives/PrivateKey.js'
|
|
3
3
|
import {
|
|
4
4
|
ProtoWallet,
|
|
5
5
|
WalletInterface,
|
|
6
|
-
|
|
7
6
|
CreateActionResult,
|
|
8
|
-
|
|
9
7
|
SignActionResult,
|
|
10
|
-
|
|
11
8
|
AbortActionResult,
|
|
12
|
-
|
|
13
9
|
ListActionsResult,
|
|
14
|
-
|
|
15
10
|
InternalizeActionResult,
|
|
16
|
-
|
|
17
11
|
ListOutputsResult,
|
|
18
|
-
|
|
19
12
|
RelinquishOutputResult,
|
|
20
|
-
|
|
21
13
|
AcquireCertificateResult,
|
|
22
|
-
|
|
23
14
|
ListCertificatesResult,
|
|
24
|
-
|
|
25
15
|
ProveCertificateResult,
|
|
26
|
-
|
|
27
16
|
RelinquishCertificateResult,
|
|
28
|
-
|
|
29
17
|
DiscoverCertificatesResult,
|
|
30
|
-
|
|
31
18
|
GetHeightResult,
|
|
32
|
-
|
|
33
19
|
GetHeaderResult,
|
|
34
20
|
KeyDeriverApi,
|
|
35
21
|
KeyDeriver,
|
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
|
-
import
|
|
2
|
+
import * as Utils from '../../primitives/utils.js'
|
|
3
|
+
import Random from '../../primitives/Random.js'
|
|
4
|
+
import P2PKH from '../../script/templates/P2PKH.js'
|
|
5
|
+
import PublicKey from '../../primitives/PublicKey.js'
|
|
6
|
+
import { WalletInterface } from '../../wallet/Wallet.interfaces.js'
|
|
7
|
+
import { createNonce } from '../utils/createNonce.js'
|
|
3
8
|
import { Peer } from '../Peer.js'
|
|
4
9
|
import { SimplifiedFetchTransport } from '../transports/SimplifiedFetchTransport.js'
|
|
5
10
|
import { SessionManager } from '../SessionManager.js'
|
|
6
11
|
import { RequestedCertificateSet } from '../types.js'
|
|
7
12
|
import { VerifiableCertificate } from '../certificates/VerifiableCertificate.js'
|
|
8
13
|
import { Writer } from '../../primitives/utils.js'
|
|
14
|
+
import { getVerifiableCertificates } from '../utils/index.js'
|
|
9
15
|
|
|
10
|
-
|
|
11
|
-
method?: string
|
|
12
|
-
headers?: Record<string, string
|
|
13
|
-
body?: any
|
|
16
|
+
interface SimplifiedFetchRequestOptions {
|
|
17
|
+
method?: string
|
|
18
|
+
headers?: Record<string, string>
|
|
19
|
+
body?: any
|
|
14
20
|
retryCounter?: number
|
|
15
21
|
}
|
|
16
|
-
|
|
22
|
+
|
|
23
|
+
interface AuthPeer {
|
|
24
|
+
peer: Peer
|
|
25
|
+
identityKey?: string
|
|
26
|
+
supportsMutualAuth?: boolean
|
|
27
|
+
pendingCertificateRequests: Array<true>
|
|
28
|
+
}
|
|
17
29
|
|
|
18
30
|
const PAYMENT_VERSION = '1.0'
|
|
19
31
|
|
|
@@ -26,11 +38,11 @@ const PAYMENT_VERSION = '1.0'
|
|
|
26
38
|
* and sending BSV payment transactions when necessary.
|
|
27
39
|
*/
|
|
28
40
|
export class AuthFetch {
|
|
29
|
-
private sessionManager: SessionManager
|
|
30
|
-
private wallet: WalletInterface
|
|
41
|
+
private readonly sessionManager: SessionManager
|
|
42
|
+
private readonly wallet: WalletInterface
|
|
31
43
|
private callbacks: Record<string, { resolve: Function, reject: Function }> = {}
|
|
32
|
-
private certificatesReceived: VerifiableCertificate[] = []
|
|
33
|
-
private requestedCertificates?: RequestedCertificateSet
|
|
44
|
+
private readonly certificatesReceived: VerifiableCertificate[] = []
|
|
45
|
+
private readonly requestedCertificates?: RequestedCertificateSet
|
|
34
46
|
peers: Record<string, AuthPeer> = {}
|
|
35
47
|
|
|
36
48
|
/**
|
|
@@ -58,7 +70,7 @@ export class AuthFetch {
|
|
|
58
70
|
* @throws Will throw an error if unsupported headers are used or other validation fails.
|
|
59
71
|
*/
|
|
60
72
|
async fetch(url: string, config: SimplifiedFetchRequestOptions = {}): Promise<Response> {
|
|
61
|
-
if (config.retryCounter) {
|
|
73
|
+
if (typeof config.retryCounter === 'number') {
|
|
62
74
|
if (config.retryCounter <= 0) {
|
|
63
75
|
throw new Error('Request failed after maximum number of retries.')
|
|
64
76
|
}
|
|
@@ -79,13 +91,28 @@ export class AuthFetch {
|
|
|
79
91
|
// Create a peer for the request
|
|
80
92
|
const newTransport = new SimplifiedFetchTransport(baseURL)
|
|
81
93
|
peerToUse = {
|
|
82
|
-
peer: new Peer(this.wallet, newTransport, this.requestedCertificates, this.sessionManager)
|
|
94
|
+
peer: new Peer(this.wallet, newTransport, this.requestedCertificates, this.sessionManager),
|
|
95
|
+
pendingCertificateRequests: []
|
|
83
96
|
}
|
|
84
97
|
this.peers[baseURL] = peerToUse
|
|
85
|
-
|
|
98
|
+
this.peers[baseURL].peer.listenForCertificatesReceived((senderPublicKey: string, certs: VerifiableCertificate[]) => {
|
|
86
99
|
this.certificatesReceived.push(...certs)
|
|
87
|
-
// peerToUse.peer.stopListeningForCertificatesReceived()
|
|
88
100
|
})
|
|
101
|
+
this.peers[baseURL].peer.listenForCertificatesRequested((async (verifier: string, requestedCertificates: RequestedCertificateSet) => {
|
|
102
|
+
try {
|
|
103
|
+
this.peers[baseURL].pendingCertificateRequests.push(true)
|
|
104
|
+
const certificatesToInclude = await getVerifiableCertificates(
|
|
105
|
+
this.wallet,
|
|
106
|
+
requestedCertificates,
|
|
107
|
+
verifier
|
|
108
|
+
)
|
|
109
|
+
await this.peers[baseURL].peer.sendCertificateResponse(verifier, certificatesToInclude)
|
|
110
|
+
} finally {
|
|
111
|
+
// Give the backend 500 ms to process the certificates we just sent, before releasing the queue entry
|
|
112
|
+
await new Promise(resolve => setTimeout(resolve, 500))
|
|
113
|
+
this.peers[baseURL].pendingCertificateRequests.shift()
|
|
114
|
+
}
|
|
115
|
+
}) as Function)
|
|
89
116
|
} else {
|
|
90
117
|
// Check if there's a session associated with this baseURL
|
|
91
118
|
if (this.peers[baseURL].supportsMutualAuth === false) {
|
|
@@ -174,6 +201,20 @@ export class AuthFetch {
|
|
|
174
201
|
delete this.callbacks[requestNonceAsBase64]
|
|
175
202
|
})
|
|
176
203
|
|
|
204
|
+
// Before sending general messages to the peer, ensure that no certificate requests are pending.
|
|
205
|
+
// This way, the user would need to choose to either allow or reject the certificate request first.
|
|
206
|
+
// If the server has a resource that requires certificates to be sent before access would be granted,
|
|
207
|
+
// this makes sure the user has a chance to send the certificates before the resource is requested.
|
|
208
|
+
if (peerToUse.pendingCertificateRequests.length > 0) {
|
|
209
|
+
await new Promise(resolve => {
|
|
210
|
+
setInterval(() => {
|
|
211
|
+
if (peerToUse.pendingCertificateRequests.length === 0) {
|
|
212
|
+
resolve()
|
|
213
|
+
}
|
|
214
|
+
}, 100) // Check every 100 ms for the user to finish responding
|
|
215
|
+
})
|
|
216
|
+
}
|
|
217
|
+
|
|
177
218
|
// Send the request, now that all listeners are set up
|
|
178
219
|
await peerToUse.peer.toPeer(writer.toArray(), peerToUse.identityKey).catch(async error => {
|
|
179
220
|
if (error.message.includes('Session not found for nonce')) {
|
|
@@ -217,7 +258,7 @@ export class AuthFetch {
|
|
|
217
258
|
const baseURL = parsedUrl.origin
|
|
218
259
|
|
|
219
260
|
let peerToUse: { peer: Peer; identityKey?: string }
|
|
220
|
-
if (this.peers[baseURL]) {
|
|
261
|
+
if (typeof this.peers[baseURL] !== 'undefined') {
|
|
221
262
|
peerToUse = { peer: this.peers[baseURL].peer }
|
|
222
263
|
} else {
|
|
223
264
|
const newTransport = new SimplifiedFetchTransport(baseURL)
|
|
@@ -233,7 +274,7 @@ export class AuthFetch {
|
|
|
233
274
|
}
|
|
234
275
|
|
|
235
276
|
// Return a promise that resolves when certificates are received
|
|
236
|
-
return new Promise<VerifiableCertificate[]>(async (resolve, reject) => {
|
|
277
|
+
return await new Promise<VerifiableCertificate[]>((async (resolve, reject) => {
|
|
237
278
|
// Set up the listener before making the request
|
|
238
279
|
const callbackId = peerToUse.peer.listenForCertificatesReceived((_senderPublicKey: string, certs: VerifiableCertificate[]) => {
|
|
239
280
|
peerToUse.peer.stopListeningForCertificatesReceived(callbackId)
|
|
@@ -248,7 +289,7 @@ export class AuthFetch {
|
|
|
248
289
|
peerToUse.peer.stopListeningForCertificatesReceived(callbackId)
|
|
249
290
|
reject(err)
|
|
250
291
|
}
|
|
251
|
-
})
|
|
292
|
+
}) as Function)
|
|
252
293
|
}
|
|
253
294
|
|
|
254
295
|
/**
|
|
@@ -513,4 +554,4 @@ export class AuthFetch {
|
|
|
513
554
|
// 9. Fallback
|
|
514
555
|
throw new Error('Unsupported body type in this SimplifiedFetch implementation.')
|
|
515
556
|
}
|
|
516
|
-
}
|
|
557
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
// @ts-ignore
|
|
3
3
|
import { AuthMessage, RequestedCertificateSet, Transport } from "../types.js"
|
|
4
|
-
import
|
|
4
|
+
import * as Utils from '../../primitives/utils.js'
|
|
5
5
|
|
|
6
6
|
const SUCCESS_STATUS_CODES = [200, 402]
|
|
7
7
|
|
|
@@ -42,25 +42,38 @@ export class SimplifiedFetchTransport implements Transport {
|
|
|
42
42
|
if (!this.onDataCallback) {
|
|
43
43
|
throw new Error('Listen before you start speaking. God gave you two ears and one mouth for a reason.')
|
|
44
44
|
}
|
|
45
|
-
|
|
46
45
|
if (message.messageType !== 'general') {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
46
|
+
return new Promise(async (resolve, reject) => {
|
|
47
|
+
try {
|
|
48
|
+
const responsePromise = this.fetchClient(`${this.baseUrl}/.well-known/auth`, {
|
|
49
|
+
method: 'POST',
|
|
50
|
+
headers: {
|
|
51
|
+
'Content-Type': 'application/json'
|
|
52
|
+
},
|
|
53
|
+
body: JSON.stringify(message)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
if (message.messageType !== "initialRequest") {
|
|
57
|
+
resolve()
|
|
58
|
+
}
|
|
59
|
+
const response = await responsePromise
|
|
60
|
+
|
|
61
|
+
// Handle the response if data is received and callback is set
|
|
62
|
+
if (response.ok && this.onDataCallback) {
|
|
63
|
+
const responseMessage = await response.json()
|
|
64
|
+
this.onDataCallback(responseMessage as AuthMessage)
|
|
65
|
+
} else {
|
|
66
|
+
// Server may be a non authenticated server
|
|
67
|
+
throw new Error('HTTP server failed to authenticate')
|
|
68
|
+
}
|
|
69
|
+
if (message.messageType === "initialRequest") {
|
|
70
|
+
resolve()
|
|
71
|
+
}
|
|
72
|
+
} catch (e) {
|
|
73
|
+
reject(e)
|
|
74
|
+
return
|
|
59
75
|
}
|
|
60
|
-
}
|
|
61
|
-
// Server may be a non authenticated server
|
|
62
|
-
throw new Error('HTTP server failed to authenticate')
|
|
63
|
-
}
|
|
76
|
+
})
|
|
64
77
|
} else {
|
|
65
78
|
// Parse message payload
|
|
66
79
|
const httpRequest = this.deserializeRequestPayload(message.payload)
|
|
@@ -105,7 +118,6 @@ export class SimplifiedFetchTransport implements Transport {
|
|
|
105
118
|
}
|
|
106
119
|
}
|
|
107
120
|
|
|
108
|
-
|
|
109
121
|
// Send the actual fetch request to the server
|
|
110
122
|
const response = await this.fetchClient(url, {
|
|
111
123
|
method: httpRequestWithAuthHeaders.method,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Utils,
|
|
3
|
-
Random,
|
|
4
2
|
WalletInterface,
|
|
5
3
|
WalletCounterparty,
|
|
6
4
|
Base64String
|
|
7
|
-
} from '
|
|
5
|
+
} from '../../wallet/Wallet.interfaces.js'
|
|
6
|
+
import * as Utils from '../../primitives/utils.js'
|
|
7
|
+
import Random from '../../primitives/Random.js'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Creates a nonce derived from a wallet
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as Utils from '../../primitives/utils.js'
|
|
2
|
+
import { WalletInterface, WalletCounterparty, Base64String } from '../../wallet/Wallet.interfaces.js'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Verifies a nonce derived from a wallet
|
package/src/primitives/utils.ts
CHANGED
|
@@ -359,7 +359,7 @@ export const fromBase58Check = (
|
|
|
359
359
|
str: string,
|
|
360
360
|
enc?: 'hex',
|
|
361
361
|
prefixLength: number = 1
|
|
362
|
-
):
|
|
362
|
+
): { data: number[] | string, prefix: number[] | string } => {
|
|
363
363
|
const bin = fromBase58(str)
|
|
364
364
|
let prefix: string | number[] = bin.slice(0, prefixLength)
|
|
365
365
|
let data: string | number[] = bin.slice(prefixLength, -4)
|