@bsv/wallet-toolbox 1.1.12 → 1.1.14
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/.github/workflows/push.yaml +2 -2
- package/README.md +3 -22
- package/docs/README.md +16 -10
- package/docs/client.md +490 -382
- package/docs/open-rpc/index.html +46 -0
- package/docs/services.md +236 -211
- package/docs/setup.md +51 -34
- package/docs/storage.md +30 -5
- package/docs/wallet.md +490 -382
- package/out/src/SetupClient.d.ts +9 -0
- package/out/src/SetupClient.d.ts.map +1 -1
- package/out/src/SetupClient.js +34 -18
- package/out/src/SetupClient.js.map +1 -1
- package/out/src/Wallet.d.ts +6 -0
- package/out/src/Wallet.d.ts.map +1 -1
- package/out/src/Wallet.js +57 -0
- package/out/src/Wallet.js.map +1 -1
- package/out/src/sdk/WalletServices.interfaces.d.ts +18 -13
- package/out/src/sdk/WalletServices.interfaces.d.ts.map +1 -1
- package/out/src/services/Services.d.ts +4 -11
- package/out/src/services/Services.d.ts.map +1 -1
- package/out/src/services/Services.js +19 -37
- package/out/src/services/Services.js.map +1 -1
- package/out/src/services/__tests/ARC.test.d.ts +2 -0
- package/out/src/services/__tests/ARC.test.d.ts.map +1 -0
- package/out/src/services/__tests/ARC.test.js +98 -0
- package/out/src/services/__tests/ARC.test.js.map +1 -0
- package/out/src/services/__tests/arcServices.test.d.ts +2 -0
- package/out/src/services/__tests/arcServices.test.d.ts.map +1 -0
- package/out/src/services/__tests/arcServices.test.js +7 -0
- package/out/src/services/__tests/arcServices.test.js.map +1 -0
- package/out/src/services/__tests/postBeef.test.js +45 -7
- package/out/src/services/__tests/postBeef.test.js.map +1 -1
- package/out/src/services/createDefaultWalletServicesOptions.d.ts +1 -0
- package/out/src/services/createDefaultWalletServicesOptions.d.ts.map +1 -1
- package/out/src/services/createDefaultWalletServicesOptions.js +16 -4
- package/out/src/services/createDefaultWalletServicesOptions.js.map +1 -1
- package/out/src/services/providers/ARC.d.ts +91 -0
- package/out/src/services/providers/ARC.d.ts.map +1 -0
- package/out/src/services/providers/ARC.js +192 -0
- package/out/src/services/providers/ARC.js.map +1 -0
- package/out/src/services/providers/SdkWhatsOnChain.d.ts +21 -0
- package/out/src/services/providers/SdkWhatsOnChain.d.ts.map +1 -0
- package/out/src/services/providers/SdkWhatsOnChain.js +67 -0
- package/out/src/services/providers/SdkWhatsOnChain.js.map +1 -0
- package/out/src/services/providers/WhatsOnChain.d.ts +35 -0
- package/out/src/services/providers/WhatsOnChain.d.ts.map +1 -0
- package/out/src/services/providers/WhatsOnChain.js +266 -0
- package/out/src/services/providers/WhatsOnChain.js.map +1 -0
- package/out/src/services/providers/__tests/WhatsOnChain.test.d.ts +2 -0
- package/out/src/services/providers/__tests/WhatsOnChain.test.d.ts.map +1 -0
- package/out/src/services/providers/__tests/WhatsOnChain.test.js +176 -0
- package/out/src/services/providers/__tests/WhatsOnChain.test.js.map +1 -0
- package/out/src/signer/methods/createAction.js +3 -3
- package/out/src/signer/methods/createAction.js.map +1 -1
- package/out/src/signer/methods/signAction.js +1 -1
- package/out/src/signer/methods/signAction.js.map +1 -1
- package/out/src/storage/methods/createAction.d.ts.map +1 -1
- package/out/src/storage/methods/createAction.js +9 -2
- package/out/src/storage/methods/createAction.js.map +1 -1
- package/out/src/storage/methods/generateChange.d.ts +12 -1
- package/out/src/storage/methods/generateChange.d.ts.map +1 -1
- package/out/src/storage/methods/generateChange.js +24 -1
- package/out/src/storage/methods/generateChange.js.map +1 -1
- package/out/src/storage/methods/processAction.d.ts.map +1 -1
- package/out/src/storage/methods/processAction.js +1 -1
- package/out/src/storage/methods/processAction.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/ProvenTxTests.test.js +0 -1
- package/out/src/storage/schema/entities/__tests/ProvenTxTests.test.js.map +1 -1
- package/out/src/storage/sync/StorageMySQLDojoReader.js +1 -1
- package/out/src/storage/sync/StorageMySQLDojoReader.js.map +1 -1
- package/out/src/utility/{ScriptTemplateSABPPP.d.ts → ScriptTemplateBRC29.d.ts} +6 -6
- package/out/src/utility/ScriptTemplateBRC29.d.ts.map +1 -0
- package/out/src/utility/{ScriptTemplateSABPPP.js → ScriptTemplateBRC29.js} +4 -4
- package/out/src/utility/ScriptTemplateBRC29.js.map +1 -0
- package/out/src/utility/index.all.d.ts +1 -1
- package/out/src/utility/index.all.d.ts.map +1 -1
- package/out/src/utility/index.all.js +1 -1
- package/out/src/utility/index.all.js.map +1 -1
- package/out/src/utility/index.client.d.ts +1 -1
- package/out/src/utility/index.client.d.ts.map +1 -1
- package/out/src/utility/index.client.js +1 -1
- package/out/src/utility/index.client.js.map +1 -1
- package/out/src/utility/utilityHelpers.js +1 -1
- package/out/src/utility/utilityHelpers.js.map +1 -1
- package/out/test/Wallet/StorageClient/storageClient.man.test.js +22 -3
- package/out/test/Wallet/StorageClient/storageClient.man.test.js.map +1 -1
- package/out/test/Wallet/live/walletLive.man.test.js +2 -2
- package/out/test/Wallet/live/walletLive.man.test.js.map +1 -1
- package/out/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.js +40 -0
- package/out/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.js.map +1 -1
- package/out/test/services/Services.test.js +0 -31
- package/out/test/services/Services.test.js.map +1 -1
- package/out/test/utils/TestUtilsWalletStorage.d.ts +26 -18
- package/out/test/utils/TestUtilsWalletStorage.d.ts.map +1 -1
- package/out/test/utils/TestUtilsWalletStorage.js +135 -27
- package/out/test/utils/TestUtilsWalletStorage.js.map +1 -1
- package/out/test/wallet/list/listActions2.test.js +36 -2
- package/out/test/wallet/list/listActions2.test.js.map +1 -1
- package/out/tsconfig.all.tsbuildinfo +1 -1
- package/package.json +5 -7
- package/src/SetupClient.ts +41 -21
- package/src/Wallet.ts +66 -2
- package/src/sdk/WalletServices.interfaces.ts +19 -14
- package/src/services/Services.ts +23 -62
- package/src/services/__tests/ARC.test.ts +110 -0
- package/src/services/__tests/arcServices.test.ts +8 -0
- package/src/services/__tests/postBeef.test.ts +47 -9
- package/src/services/createDefaultWalletServicesOptions.ts +19 -6
- package/src/services/providers/ARC.ts +289 -0
- package/src/services/providers/SdkWhatsOnChain.ts +96 -0
- package/src/services/providers/WhatsOnChain.ts +369 -0
- package/src/services/providers/__tests/WhatsOnChain.test.ts +227 -0
- package/src/signer/methods/createAction.ts +4 -4
- package/src/signer/methods/signAction.ts +2 -2
- package/src/storage/methods/createAction.ts +26 -4
- package/src/storage/methods/generateChange.ts +42 -2
- package/src/storage/methods/processAction.ts +2 -1
- package/src/storage/schema/entities/__tests/ProvenTxTests.test.ts +0 -1
- package/src/storage/sync/StorageMySQLDojoReader.ts +1 -1
- package/src/utility/{ScriptTemplateSABPPP.ts → ScriptTemplateBRC29.ts} +6 -8
- package/src/utility/index.all.ts +1 -1
- package/src/utility/index.client.ts +1 -1
- package/src/utility/utilityHelpers.ts +1 -1
- package/test/Wallet/StorageClient/storageClient.man.test.ts +30 -4
- package/test/Wallet/live/walletLive.man.test.ts +3 -3
- package/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.ts +54 -0
- package/test/services/Services.test.ts +0 -30
- package/test/utils/TestUtilsWalletStorage.ts +175 -45
- package/test/wallet/list/listActions2.test.ts +4 -7
- package/out/src/services/__tests/postBeefToArcTaal.test.d.ts +0 -2
- package/out/src/services/__tests/postBeefToArcTaal.test.d.ts.map +0 -1
- package/out/src/services/__tests/postBeefToArcTaal.test.js +0 -479
- package/out/src/services/__tests/postBeefToArcTaal.test.js.map +0 -1
- package/out/src/services/__tests/postTxs.test.d.ts +0 -2
- package/out/src/services/__tests/postTxs.test.d.ts.map +0 -1
- package/out/src/services/__tests/postTxs.test.js +0 -28
- package/out/src/services/__tests/postTxs.test.js.map +0 -1
- package/out/src/services/providers/arcServices.d.ts +0 -62
- package/out/src/services/providers/arcServices.d.ts.map +0 -1
- package/out/src/services/providers/arcServices.js +0 -375
- package/out/src/services/providers/arcServices.js.map +0 -1
- package/out/src/services/providers/whatsonchain.d.ts +0 -17
- package/out/src/services/providers/whatsonchain.d.ts.map +0 -1
- package/out/src/services/providers/whatsonchain.js +0 -130
- package/out/src/services/providers/whatsonchain.js.map +0 -1
- package/out/src/utility/ScriptTemplateSABPPP.d.ts.map +0 -1
- package/out/src/utility/ScriptTemplateSABPPP.js.map +0 -1
- package/out/test/examples/README.man.test.d.ts +0 -2
- package/out/test/examples/README.man.test.d.ts.map +0 -1
- package/out/test/examples/README.man.test.js +0 -47
- package/out/test/examples/README.man.test.js.map +0 -1
- package/src/services/__tests/postBeefToArcTaal.test.ts +0 -487
- package/src/services/__tests/postTxs.test.ts +0 -28
- package/src/services/providers/arcServices.ts +0 -578
- package/src/services/providers/whatsonchain.ts +0 -170
- package/test/examples/README.man.test.ts +0 -53
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
TableTransaction,
|
|
28
28
|
validateStorageFeeModel,
|
|
29
29
|
verifyId,
|
|
30
|
+
verifyInteger,
|
|
30
31
|
verifyNumber,
|
|
31
32
|
verifyOne,
|
|
32
33
|
verifyOneOrNone,
|
|
@@ -35,7 +36,8 @@ import {
|
|
|
35
36
|
import {
|
|
36
37
|
generateChangeSdk,
|
|
37
38
|
GenerateChangeSdkChangeInput,
|
|
38
|
-
GenerateChangeSdkParams
|
|
39
|
+
GenerateChangeSdkParams,
|
|
40
|
+
maxPossibleSatoshis
|
|
39
41
|
} from './generateChange'
|
|
40
42
|
|
|
41
43
|
export async function createAction(
|
|
@@ -109,8 +111,19 @@ export async function createAction(
|
|
|
109
111
|
transactionId: newTx.transactionId!
|
|
110
112
|
}
|
|
111
113
|
|
|
112
|
-
const {
|
|
113
|
-
|
|
114
|
+
const {
|
|
115
|
+
allocatedChange,
|
|
116
|
+
changeOutputs,
|
|
117
|
+
derivationPrefix,
|
|
118
|
+
maxPossibleSatoshisAdjustment
|
|
119
|
+
} = await fundNewTransactionSdk(storage, userId, vargs, ctx)
|
|
120
|
+
|
|
121
|
+
if (maxPossibleSatoshisAdjustment) {
|
|
122
|
+
const a = maxPossibleSatoshisAdjustment
|
|
123
|
+
if (ctx.xoutputs[a.fixedOutputIndex].satoshis !== maxPossibleSatoshis)
|
|
124
|
+
throw new sdk.WERR_INTERNAL()
|
|
125
|
+
ctx.xoutputs[a.fixedOutputIndex].satoshis = a.satoshis
|
|
126
|
+
}
|
|
114
127
|
|
|
115
128
|
// The satoshis of the transaction is the satoshis we get back in change minus the satoshis we spend.
|
|
116
129
|
const satoshis =
|
|
@@ -443,7 +456,7 @@ async function createNewOutputs(
|
|
|
443
456
|
}
|
|
444
457
|
|
|
445
458
|
const ro: sdk.StorageCreateTransactionSdkOutput = {
|
|
446
|
-
vout:
|
|
459
|
+
vout: verifyInteger(o.vout),
|
|
447
460
|
satoshis: verifyTruthy(o.satoshis),
|
|
448
461
|
lockingScript: !o.lockingScript ? '' : asString(o.lockingScript),
|
|
449
462
|
providedBy: verifyTruthy(o.providedBy) as sdk.StorageProvidedBy,
|
|
@@ -767,6 +780,10 @@ async function fundNewTransactionSdk(
|
|
|
767
780
|
allocatedChange: TableOutput[]
|
|
768
781
|
changeOutputs: TableOutput[]
|
|
769
782
|
derivationPrefix: string
|
|
783
|
+
maxPossibleSatoshisAdjustment?: {
|
|
784
|
+
fixedOutputIndex: number
|
|
785
|
+
satoshis: number
|
|
786
|
+
}
|
|
770
787
|
}> {
|
|
771
788
|
const params: GenerateChangeSdkParams = {
|
|
772
789
|
fixedInputs: ctx.xinputs.map(xi => ({
|
|
@@ -891,7 +908,12 @@ async function fundNewTransactionSdk(
|
|
|
891
908
|
allocatedChange: TableOutput[]
|
|
892
909
|
changeOutputs: TableOutput[]
|
|
893
910
|
derivationPrefix: string
|
|
911
|
+
maxPossibleSatoshisAdjustment?: {
|
|
912
|
+
fixedOutputIndex: number
|
|
913
|
+
satoshis: number
|
|
914
|
+
}
|
|
894
915
|
} = {
|
|
916
|
+
maxPossibleSatoshisAdjustment: gcr.maxPossibleSatoshisAdjustment,
|
|
895
917
|
allocatedChange: gcr.allocatedChangeInputs.map(i => outputs[i.outputId]),
|
|
896
918
|
changeOutputs: gcr.changeOutputs.map(
|
|
897
919
|
(o, i) =>
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { sdk, validateStorageFeeModel } from '../../index.client'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* An output of this satoshis amount will be adjusted to the largest fundable amount.
|
|
5
|
+
*/
|
|
6
|
+
export const maxPossibleSatoshis = 2099999999999999
|
|
7
|
+
|
|
3
8
|
export interface GenerateChangeSdkResult {
|
|
4
9
|
allocatedChangeInputs: GenerateChangeSdkChangeInput[]
|
|
5
10
|
changeOutputs: GenerateChangeSdkChangeOutput[]
|
|
6
11
|
size: number
|
|
7
12
|
fee: number
|
|
8
13
|
satsPerKb: number
|
|
14
|
+
maxPossibleSatoshisAdjustment?: {
|
|
15
|
+
fixedOutputIndex: number
|
|
16
|
+
satoshis: number
|
|
17
|
+
}
|
|
9
18
|
}
|
|
10
19
|
|
|
11
20
|
/**
|
|
@@ -38,7 +47,7 @@ export async function generateChangeSdk(
|
|
|
38
47
|
|
|
39
48
|
// eslint-disable-next-line no-useless-catch
|
|
40
49
|
try {
|
|
41
|
-
validateGenerateChangeSdkParams(params)
|
|
50
|
+
const vgcpr = validateGenerateChangeSdkParams(params)
|
|
42
51
|
|
|
43
52
|
const satsPerKb = params.feeModel.value || 0
|
|
44
53
|
|
|
@@ -269,6 +278,20 @@ export async function generateChangeSdk(
|
|
|
269
278
|
*/
|
|
270
279
|
await fundTransaction()
|
|
271
280
|
|
|
281
|
+
if (feeExcess() < 0 && vgcpr.hasMaxPossibleOutput !== undefined) {
|
|
282
|
+
// Reduce the fixed output with satoshis of maxPossibleSatoshis to what will just fund the transaction...
|
|
283
|
+
if (
|
|
284
|
+
fixedOutputs[vgcpr.hasMaxPossibleOutput].satoshis !==
|
|
285
|
+
maxPossibleSatoshis
|
|
286
|
+
)
|
|
287
|
+
throw new sdk.WERR_INTERNAL()
|
|
288
|
+
fixedOutputs[vgcpr.hasMaxPossibleOutput].satoshis += feeExcess()
|
|
289
|
+
r.maxPossibleSatoshisAdjustment = {
|
|
290
|
+
fixedOutputIndex: vgcpr.hasMaxPossibleOutput,
|
|
291
|
+
satoshis: fixedOutputs[vgcpr.hasMaxPossibleOutput].satoshis
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
272
295
|
/**
|
|
273
296
|
* Trigger an account funding event if we don't have enough to cover this transaction.
|
|
274
297
|
*/
|
|
@@ -448,11 +471,18 @@ export interface GenerateChangeSdkChangeOutput {
|
|
|
448
471
|
lockingScriptLength: number
|
|
449
472
|
}
|
|
450
473
|
|
|
474
|
+
export interface ValidateGenerateChangeSdkParamsResult {
|
|
475
|
+
hasMaxPossibleOutput?: number
|
|
476
|
+
}
|
|
477
|
+
|
|
451
478
|
export function validateGenerateChangeSdkParams(
|
|
452
479
|
params: GenerateChangeSdkParams
|
|
453
|
-
) {
|
|
480
|
+
): ValidateGenerateChangeSdkParamsResult {
|
|
454
481
|
if (!Array.isArray(params.fixedInputs))
|
|
455
482
|
throw new sdk.WERR_INVALID_PARAMETER('fixedInputs', 'an array of objects')
|
|
483
|
+
|
|
484
|
+
const r: ValidateGenerateChangeSdkParamsResult = {}
|
|
485
|
+
|
|
456
486
|
params.fixedInputs.forEach((x, i) => {
|
|
457
487
|
sdk.validateSatoshis(x.satoshis, `fixedInputs[${i}].satoshis`)
|
|
458
488
|
sdk.validateInteger(
|
|
@@ -473,6 +503,14 @@ export function validateGenerateChangeSdkParams(
|
|
|
473
503
|
undefined,
|
|
474
504
|
0
|
|
475
505
|
)
|
|
506
|
+
if (x.satoshis === maxPossibleSatoshis) {
|
|
507
|
+
if (r.hasMaxPossibleOutput !== undefined)
|
|
508
|
+
throw new sdk.WERR_INVALID_PARAMETER(
|
|
509
|
+
`fixedOutputs[${i}].satoshis`,
|
|
510
|
+
`valid satoshis amount. Only one 'maxPossibleSatoshis' output allowed.`
|
|
511
|
+
)
|
|
512
|
+
r.hasMaxPossibleOutput = i
|
|
513
|
+
}
|
|
476
514
|
})
|
|
477
515
|
|
|
478
516
|
params.feeModel = validateStorageFeeModel(params.feeModel)
|
|
@@ -492,6 +530,8 @@ export function validateGenerateChangeSdkParams(
|
|
|
492
530
|
params.changeUnlockingScriptLength,
|
|
493
531
|
`changeUnlockingScriptLength`
|
|
494
532
|
)
|
|
533
|
+
|
|
534
|
+
return r
|
|
495
535
|
}
|
|
496
536
|
|
|
497
537
|
export interface GenerateChangeSdkStorageChange
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
TxScriptOffsets,
|
|
25
25
|
validateStorageFeeModel,
|
|
26
26
|
verifyId,
|
|
27
|
+
verifyInteger,
|
|
27
28
|
verifyNumber,
|
|
28
29
|
verifyOne,
|
|
29
30
|
verifyOneOrNone,
|
|
@@ -359,7 +360,7 @@ async function validateCommitNewTxToStorageArgs(
|
|
|
359
360
|
// outputs spendable will be updated for change to true and all others to !!o.tracked when tx has been broadcast
|
|
360
361
|
// MAX_OUTPUTSCRIPT_LENGTH is limit for scripts left in outputs table
|
|
361
362
|
for (const o of vargs.outputOutputs) {
|
|
362
|
-
const vout =
|
|
363
|
+
const vout = verifyInteger(o.vout)
|
|
363
364
|
const offset = vargs.txScriptOffsets.outputs[vout]
|
|
364
365
|
const rawTxScript = asString(
|
|
365
366
|
vargs.rawTx.slice(offset.offset, offset.offset + offset.length)
|
|
@@ -100,7 +100,6 @@ describe('ProvenTx class method tests', () => {
|
|
|
100
100
|
getHeight: async () => height,
|
|
101
101
|
getBsvExchangeRate: async () => 0,
|
|
102
102
|
getFiatExchangeRate: async () => 1,
|
|
103
|
-
postTxs: async () => [],
|
|
104
103
|
postBeef: async () => [],
|
|
105
104
|
getUtxoStatus: async () => ({
|
|
106
105
|
name: 'mock-service',
|
|
@@ -298,7 +298,7 @@ export class StorageMySQLDojoReader extends StorageReader {
|
|
|
298
298
|
spendable: !!d.spendable,
|
|
299
299
|
change: d.providedBy !== 'you' && d.purpose === 'change',
|
|
300
300
|
outputDescription: (d.description || '').trim(),
|
|
301
|
-
vout: verifyInteger(d.vout),
|
|
301
|
+
vout: verifyInteger(typeof d.vout !== 'number' ? 9999 : d.vout),
|
|
302
302
|
satoshis: verifyInteger(d.amount),
|
|
303
303
|
providedBy: verifyTruthy(d.providedBy || '')
|
|
304
304
|
.trim()
|
|
@@ -9,27 +9,25 @@ import {
|
|
|
9
9
|
LockingScript,
|
|
10
10
|
P2PKH,
|
|
11
11
|
PrivateKey,
|
|
12
|
-
Script
|
|
13
|
-
Transaction,
|
|
14
|
-
UnlockingScript
|
|
12
|
+
Script
|
|
15
13
|
} from '@bsv/sdk'
|
|
16
14
|
|
|
17
|
-
export
|
|
15
|
+
export const brc29ProtocolID: WalletProtocol = [2, '3241645161d8']
|
|
16
|
+
|
|
17
|
+
export interface ScriptTemplateParamsBRC29 {
|
|
18
18
|
derivationPrefix?: string
|
|
19
19
|
derivationSuffix?: string
|
|
20
20
|
keyDeriver: KeyDeriverApi
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export const brc29ProtocolID: WalletProtocol = [2, '3241645161d8']
|
|
24
|
-
|
|
25
23
|
/**
|
|
26
24
|
* Simple Authenticated BSV P2PKH Payment Protocol
|
|
27
25
|
* https://brc.dev/29
|
|
28
26
|
*/
|
|
29
|
-
export class
|
|
27
|
+
export class ScriptTemplateBRC29 implements ScriptTemplate {
|
|
30
28
|
p2pkh: P2PKH
|
|
31
29
|
|
|
32
|
-
constructor(public params:
|
|
30
|
+
constructor(public params: ScriptTemplateParamsBRC29) {
|
|
33
31
|
this.p2pkh = new P2PKH()
|
|
34
32
|
|
|
35
33
|
verifyTruthy(params.derivationPrefix)
|
package/src/utility/index.all.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
-
import { StorageClient } from '../../../src/index.all'
|
|
2
|
+
import { sdk, StorageClient } from '../../../src/index.all'
|
|
3
3
|
import { _tu, TestWalletOnly } from '../../utils/TestUtilsWalletStorage'
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -32,17 +32,17 @@ describe('walletStorageClient test', () => {
|
|
|
32
32
|
{
|
|
33
33
|
const client = new StorageClient(
|
|
34
34
|
wallet,
|
|
35
|
-
'https://staging-
|
|
35
|
+
'https://staging-storage.babbage.systems'
|
|
36
36
|
)
|
|
37
37
|
await storage.addWalletStorageProvider(client)
|
|
38
38
|
await storage.updateBackups()
|
|
39
39
|
}
|
|
40
40
|
})
|
|
41
41
|
|
|
42
|
-
test('2 create storage client wallet', async () => {
|
|
42
|
+
test('2 create storage client backup for test wallet', async () => {
|
|
43
43
|
const ctx = await _tu.createTestWalletWithStorageClient({
|
|
44
44
|
rootKeyHex: '1'.repeat(64),
|
|
45
|
-
endpointUrl: 'https://staging-
|
|
45
|
+
endpointUrl: 'https://staging-storage.babbage.systems'
|
|
46
46
|
})
|
|
47
47
|
ctxs.push(ctx)
|
|
48
48
|
const { wallet, storage } = ctx
|
|
@@ -52,4 +52,30 @@ describe('walletStorageClient test', () => {
|
|
|
52
52
|
expect(auth.userId).toBeTruthy()
|
|
53
53
|
}
|
|
54
54
|
})
|
|
55
|
+
|
|
56
|
+
test('3 create storage client backup for main wallet', async () => {
|
|
57
|
+
const filePath = process.env.MY_MAIN_FILEPATH
|
|
58
|
+
const identityKey = process.env.MY_MAIN_IDENTITY || ''
|
|
59
|
+
const rootKeyHex = env.devKeys[identityKey]
|
|
60
|
+
expect(filePath && identityKey && rootKeyHex)
|
|
61
|
+
|
|
62
|
+
const chain: sdk.Chain = 'main'
|
|
63
|
+
|
|
64
|
+
const main = await _tu.createSQLiteTestWallet({
|
|
65
|
+
filePath,
|
|
66
|
+
databaseName: 'tone42',
|
|
67
|
+
chain,
|
|
68
|
+
rootKeyHex
|
|
69
|
+
})
|
|
70
|
+
ctxs.push(main)
|
|
71
|
+
|
|
72
|
+
{
|
|
73
|
+
const client = new StorageClient(
|
|
74
|
+
main.wallet,
|
|
75
|
+
'https://storage.babbage.systems'
|
|
76
|
+
)
|
|
77
|
+
await main.storage.addWalletStorageProvider(client)
|
|
78
|
+
await main.storage.updateBackups()
|
|
79
|
+
}
|
|
80
|
+
})
|
|
55
81
|
})
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
sdk,
|
|
17
17
|
verifyOne,
|
|
18
18
|
verifyId,
|
|
19
|
-
|
|
19
|
+
ScriptTemplateBRC29,
|
|
20
20
|
randomBytesBase64,
|
|
21
21
|
randomBytes,
|
|
22
22
|
EntityProvenTxReq,
|
|
@@ -451,7 +451,7 @@ export function createWalletPaymentOutput(args: {
|
|
|
451
451
|
derivationSuffix: string
|
|
452
452
|
lockingScript: string
|
|
453
453
|
} {
|
|
454
|
-
const t = new
|
|
454
|
+
const t = new ScriptTemplateBRC29({
|
|
455
455
|
derivationPrefix: randomBytesBase64(8),
|
|
456
456
|
derivationSuffix: randomBytesBase64(8),
|
|
457
457
|
keyDeriver: new KeyDeriver(PrivateKey.fromString(args.fromRootKeyHex))
|
|
@@ -495,7 +495,7 @@ export async function createWalletPaymentAction(args: {
|
|
|
495
495
|
}> {
|
|
496
496
|
const { toIdentityKey, outputSatoshis, keyDeriver, wallet } = args
|
|
497
497
|
|
|
498
|
-
const t = new
|
|
498
|
+
const t = new ScriptTemplateBRC29({
|
|
499
499
|
derivationPrefix: randomBytesBase64(8),
|
|
500
500
|
derivationSuffix: randomBytesBase64(8),
|
|
501
501
|
keyDeriver
|
|
@@ -66,6 +66,60 @@ describe('Wallet sync tests', () => {
|
|
|
66
66
|
done0 = true
|
|
67
67
|
})
|
|
68
68
|
|
|
69
|
+
test.skip('0a sync production dojo to local MySQL', async () => {
|
|
70
|
+
console.log(
|
|
71
|
+
'Importing from production dojo to local MySQL productiondojotone'
|
|
72
|
+
)
|
|
73
|
+
const identityKeyTone = process.env.MY_MAIN_IDENTITY || ''
|
|
74
|
+
const rootKeyHex = env.devKeys[identityKeyTone]
|
|
75
|
+
const chain: sdk.Chain = 'main'
|
|
76
|
+
const connection = JSON.parse(process.env.MAIN_DOJO_CONNECTION || '')
|
|
77
|
+
const readerKnex = _tu.createMySQLFromConnection(connection)
|
|
78
|
+
const reader = new StorageMySQLDojoReader({ chain, knex: readerKnex })
|
|
79
|
+
const writer = await _tu.createMySQLTestWallet({
|
|
80
|
+
databaseName: 'productiondojotone',
|
|
81
|
+
chain: 'main',
|
|
82
|
+
rootKeyHex,
|
|
83
|
+
dropAll: true
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
const identityKey = writer.identityKey
|
|
87
|
+
await writer.storage.syncFromReader(
|
|
88
|
+
identityKey,
|
|
89
|
+
new StorageSyncReader({ identityKey }, reader)
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
await reader.destroy()
|
|
93
|
+
await writer.activeStorage.destroy()
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
test('0b sweep mysql dojo sync to new sqlite', async () => {
|
|
97
|
+
const identityKeyTone = process.env.MY_MAIN_IDENTITY || ''
|
|
98
|
+
const rootKeyHex = env.devKeys[identityKeyTone]
|
|
99
|
+
const chain: sdk.Chain = 'main'
|
|
100
|
+
|
|
101
|
+
const sweepFrom = await _tu.createMySQLTestWallet({
|
|
102
|
+
databaseName: 'productiondojotone',
|
|
103
|
+
chain: 'main',
|
|
104
|
+
rootKeyHex
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
const sweepTo = await _tu.createSQLiteTestWallet({
|
|
108
|
+
filePath: '/Users/tone/Kz/tone42.sqlite',
|
|
109
|
+
databaseName: 'tone42',
|
|
110
|
+
chain: 'main',
|
|
111
|
+
rootKeyHex
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
//await sweepTo.activeStorage.updateProvenTxReq(2, { status: 'invalid' })
|
|
115
|
+
//await sweepTo.activeStorage.updateTransactionStatus('failed', 2)
|
|
116
|
+
|
|
117
|
+
await sweepFrom.wallet.sweepTo(sweepTo.wallet)
|
|
118
|
+
|
|
119
|
+
await sweepTo.wallet.destroy()
|
|
120
|
+
await sweepFrom.wallet.destroy()
|
|
121
|
+
})
|
|
122
|
+
|
|
69
123
|
test('1 aggressively purge records from MySQL stagingdojotone', async () => {
|
|
70
124
|
await waitFor0()
|
|
71
125
|
|
|
@@ -120,34 +120,4 @@ describe('Wallet services tests', () => {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
})
|
|
123
|
-
|
|
124
|
-
test('6 postBeef', async () => {
|
|
125
|
-
for (const { chain, wallet, services } of ctxs) {
|
|
126
|
-
if (!wallet.services || !services)
|
|
127
|
-
throw new sdk.WERR_INTERNAL('test requires setup with services')
|
|
128
|
-
{
|
|
129
|
-
if (chain === 'main') {
|
|
130
|
-
const txid =
|
|
131
|
-
'b56ccf7dd0eb6bb0341cb92a2045d902106e4c2add0a4af057c85e9dfaaebddf'
|
|
132
|
-
const rawTx = await wallet.services.getRawTx(txid)
|
|
133
|
-
const mp = await wallet.services.getMerklePath(txid)
|
|
134
|
-
const beef = new Beef()
|
|
135
|
-
beef.mergeBump(mp.merklePath!)
|
|
136
|
-
beef.mergeRawTx(rawTx.rawTx!)
|
|
137
|
-
// Using postTxs as postBeef is problematic still...
|
|
138
|
-
const r = await wallet.services.postTxs(beef, [txid])
|
|
139
|
-
if (r[0].status === 'error') {
|
|
140
|
-
console.log(`
|
|
141
|
-
${r[0].error?.message}
|
|
142
|
-
${beef.toLogString()}
|
|
143
|
-
${beef.toHex()}
|
|
144
|
-
`)
|
|
145
|
-
} else {
|
|
146
|
-
expect(r[0].txidResults[0].txid).toBe(txid)
|
|
147
|
-
expect(r[0].status).toBe('success')
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
})
|
|
153
123
|
})
|