@bsv/sdk 1.3.25 → 1.3.26
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/clients/AuthFetch.js +4 -3
- package/dist/cjs/src/auth/clients/AuthFetch.js.map +1 -1
- package/dist/cjs/src/auth/utils/createNonce.js.map +1 -1
- package/dist/cjs/src/auth/utils/verifyNonce.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/auth/clients/AuthFetch.js +5 -4
- package/dist/esm/src/auth/clients/AuthFetch.js.map +1 -1
- package/dist/esm/src/auth/utils/createNonce.js.map +1 -1
- package/dist/esm/src/auth/utils/verifyNonce.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/auth/clients/AuthFetch.d.ts.map +1 -1
- package/dist/types/src/auth/utils/createNonce.d.ts +2 -2
- package/dist/types/src/auth/utils/createNonce.d.ts.map +1 -1
- package/dist/types/src/auth/utils/verifyNonce.d.ts +2 -2
- package/dist/types/src/auth/utils/verifyNonce.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/package.json +1 -1
- package/src/auth/clients/AuthFetch.ts +5 -4
- package/src/auth/utils/createNonce.ts +3 -2
- package/src/auth/utils/verifyNonce.ts +2 -2
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
|
-
import { Utils, Random, P2PKH, PublicKey, WalletInterface } from '../../../mod.js'
|
|
2
|
+
import { Utils, Random, P2PKH, PublicKey, WalletInterface, createNonce } from '../../../mod.js'
|
|
3
3
|
import { Peer } from '../Peer.js'
|
|
4
4
|
import { SimplifiedFetchTransport } from '../transports/SimplifiedFetchTransport.js'
|
|
5
5
|
import { SessionManager } from '../SessionManager.js'
|
|
@@ -397,15 +397,15 @@ export class AuthFetch {
|
|
|
397
397
|
}
|
|
398
398
|
|
|
399
399
|
// Create a random suffix for the derivation path
|
|
400
|
-
const derivationSuffix =
|
|
400
|
+
const derivationSuffix = await createNonce(this.wallet)
|
|
401
401
|
|
|
402
402
|
// Derive the script hex from the server identity key
|
|
403
403
|
const { publicKey: derivedPublicKey } = await this.wallet.getPublicKey({
|
|
404
|
-
protocolID: [2, 'wallet payment
|
|
404
|
+
protocolID: [2, '3241645161d8'], // wallet payment protocol
|
|
405
405
|
keyID: `${derivationPrefix} ${derivationSuffix}`,
|
|
406
406
|
counterparty: serverIdentityKey
|
|
407
407
|
})
|
|
408
|
-
const lockingScript = new P2PKH().lock(PublicKey.fromString(derivedPublicKey).
|
|
408
|
+
const lockingScript = new P2PKH().lock(PublicKey.fromString(derivedPublicKey).toAddress()).toHex()
|
|
409
409
|
|
|
410
410
|
// Create the payment transaction using createAction
|
|
411
411
|
const { tx } = await this.wallet.createAction({
|
|
@@ -421,6 +421,7 @@ export class AuthFetch {
|
|
|
421
421
|
config.headers = config.headers || {}
|
|
422
422
|
config.headers['x-bsv-payment'] = JSON.stringify({
|
|
423
423
|
derivationPrefix,
|
|
424
|
+
derivationSuffix,
|
|
424
425
|
transaction: Utils.toBase64(tx)
|
|
425
426
|
})
|
|
426
427
|
config.retryCounter ??= 3
|
|
@@ -2,7 +2,8 @@ import {
|
|
|
2
2
|
Utils,
|
|
3
3
|
Random,
|
|
4
4
|
WalletInterface,
|
|
5
|
-
WalletCounterparty
|
|
5
|
+
WalletCounterparty,
|
|
6
|
+
Base64String
|
|
6
7
|
} from '../../../mod.js'
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -14,7 +15,7 @@ import {
|
|
|
14
15
|
export async function createNonce(
|
|
15
16
|
wallet: WalletInterface,
|
|
16
17
|
counterparty: WalletCounterparty = 'self'
|
|
17
|
-
): Promise<
|
|
18
|
+
): Promise<Base64String> {
|
|
18
19
|
// Generate 16 random bytes for the first half of the data
|
|
19
20
|
const firstHalf = Random(16)
|
|
20
21
|
// Create an sha256 HMAC
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Utils, WalletInterface, WalletCounterparty } from '../../../mod.js'
|
|
1
|
+
import { Utils, WalletInterface, WalletCounterparty, Base64String } from '../../../mod.js'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Verifies a nonce derived from a wallet
|
|
@@ -8,7 +8,7 @@ import { Utils, WalletInterface, WalletCounterparty } from '../../../mod.js'
|
|
|
8
8
|
* @returns The status of the validation
|
|
9
9
|
*/
|
|
10
10
|
export async function verifyNonce(
|
|
11
|
-
nonce:
|
|
11
|
+
nonce: Base64String,
|
|
12
12
|
wallet: WalletInterface,
|
|
13
13
|
counterparty: WalletCounterparty = 'self'
|
|
14
14
|
): Promise<boolean> {
|