@gobob/bob-sdk 2.3.4 → 2.3.6
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/esplora.js +13 -13
- package/dist/esplora.js.map +1 -1
- package/dist/gateway/client.d.ts +4 -3
- package/dist/gateway/client.js +76 -64
- package/dist/gateway/client.js.map +1 -1
- package/dist/gateway/index.d.ts +2 -2
- package/dist/gateway/tokens.d.ts +4 -2
- package/dist/gateway/tokens.js +157 -71
- package/dist/gateway/tokens.js.map +1 -1
- package/dist/gateway/types.d.ts +8 -8
- package/dist/gateway/types.js +0 -2
- package/dist/gateway/types.js.map +1 -1
- package/dist/helpers.d.ts +2 -2
- package/dist/helpers.js +5 -3
- package/dist/helpers.js.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/inscription.d.ts +2 -2
- package/dist/inscription.js +11 -13
- package/dist/inscription.js.map +1 -1
- package/dist/ordinal-api/index.d.ts +1 -1
- package/dist/ordinal-api/index.js +11 -11
- package/dist/ordinals/commit.d.ts +2 -2
- package/dist/ordinals/index.d.ts +3 -3
- package/dist/ordinals/index.js +1 -1
- package/dist/ordinals/reveal.d.ts +3 -3
- package/dist/ordinals/reveal.js.map +1 -1
- package/dist/ordinals/signer.d.ts +1 -1
- package/dist/relay.d.ts +1 -1
- package/dist/relay.js +5 -6
- package/dist/relay.js.map +1 -1
- package/dist/scripts/relay-genesis.js +47 -47
- package/dist/scripts/relay-genesis.js.map +1 -1
- package/dist/scripts/relay-retarget.js +33 -33
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +19 -17
- package/dist/utils.js.map +1 -1
- package/dist/wallet/index.d.ts +2 -2
- package/dist/wallet/inscriptions.d.ts +2 -2
- package/dist/wallet/inscriptions.js +1 -1
- package/dist/wallet/utxo.d.ts +4 -4
- package/dist/wallet/utxo.js +13 -13
- package/dist/wallet/utxo.js.map +1 -1
- package/package.json +12 -6
package/dist/ordinals/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as bitcoin from
|
|
2
|
-
import { RemoteSigner } from
|
|
3
|
-
import { Inscription } from
|
|
1
|
+
import * as bitcoin from 'bitcoinjs-lib';
|
|
2
|
+
import { RemoteSigner } from './signer';
|
|
3
|
+
import { Inscription } from '../inscription';
|
|
4
4
|
export { RemoteSigner };
|
|
5
5
|
export declare function inscribeData(signer: RemoteSigner, toAddress: string, feeRate: number, inscription: Inscription, postage?: number): Promise<bitcoin.Transaction>;
|
package/dist/ordinals/index.js
CHANGED
|
@@ -51,7 +51,7 @@ function estimateTxSize(network, publicKey, commitTxData, toAddress, amount) {
|
|
|
51
51
|
}
|
|
52
52
|
async function inscribeData(signer, toAddress, feeRate, inscription, postage = 10000) {
|
|
53
53
|
const bitcoinNetwork = await signer.getNetwork();
|
|
54
|
-
const publicKey = Buffer.from(await signer.getPublicKey(),
|
|
54
|
+
const publicKey = Buffer.from(await signer.getPublicKey(), 'hex');
|
|
55
55
|
const commitTxData = (0, commit_1.createCommitTxData)(bitcoinNetwork, publicKey, inscription);
|
|
56
56
|
const revealTxSize = estimateTxSize(bitcoinNetwork, publicKey, commitTxData, toAddress, postage);
|
|
57
57
|
const revealFee = revealTxSize * feeRate;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as bitcoin from
|
|
2
|
-
import { RemoteSigner } from
|
|
3
|
-
import { CommitTxData } from
|
|
1
|
+
import * as bitcoin from 'bitcoinjs-lib';
|
|
2
|
+
import { RemoteSigner } from './signer';
|
|
3
|
+
import { CommitTxData } from './commit';
|
|
4
4
|
export interface CommitTxResult {
|
|
5
5
|
tx: bitcoin.Transaction;
|
|
6
6
|
outputIndex: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reveal.js","sourceRoot":"","sources":["../../src/ordinals/reveal.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,wCA4BC;
|
|
1
|
+
{"version":3,"file":"reveal.js","sourceRoot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BAA2B,CAAC,OAAO,CAAC;SAC3D,CAAC;IACN,CAAC,CAAC;AACN,CAAC,CAAC;AAbW,QAAA,eAAe,mBAa1B;AAEK,KAAK,UAAU,YAAY,CAAC,MAAoB,EAAE,YAA0B,EAAE,IAAkB;IAEnG,IAAI,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IAGvC,IAAI,CAAC,aAAa,CAAC,CAAC,EAAE,IAAA,uBAAe,EAAC,YAAY,CAAC,CAAC,CAAC;IAErD,OAAO,IAAI,CAAC,kBAAkB,EAAE,CAAC;AACrC,CAAC"}
|
package/dist/relay.d.ts
CHANGED
package/dist/relay.js
CHANGED
|
@@ -13,12 +13,11 @@ async function getBitcoinTxInfo(esploraClient, txId, forWitness) {
|
|
|
13
13
|
const locktimeBuffer = Buffer.allocUnsafe(4);
|
|
14
14
|
locktimeBuffer.writeInt32LE(tx.locktime);
|
|
15
15
|
return {
|
|
16
|
-
version: versionBuffer.toString(
|
|
17
|
-
inputVector: (0, utils_1.encodeRawInput)(tx).toString(
|
|
18
|
-
outputVector: (0, utils_1.encodeRawOutput)(tx).toString(
|
|
19
|
-
locktime: locktimeBuffer.toString(
|
|
20
|
-
witnessVector: forWitness ? (0, utils_1.encodeRawWitness)(tx).toString(
|
|
21
|
-
witnessVector: forWitness ? (0, utils_1.encodeRawWitness)(tx).toString("hex") : undefined,
|
|
16
|
+
version: versionBuffer.toString('hex'),
|
|
17
|
+
inputVector: (0, utils_1.encodeRawInput)(tx).toString('hex'),
|
|
18
|
+
outputVector: (0, utils_1.encodeRawOutput)(tx).toString('hex'),
|
|
19
|
+
locktime: locktimeBuffer.toString('hex'),
|
|
20
|
+
witnessVector: forWitness ? (0, utils_1.encodeRawWitness)(tx).toString('hex') : undefined,
|
|
22
21
|
};
|
|
23
22
|
}
|
|
24
23
|
async function getBitcoinTxProof(esploraClient, txId, txProofDifficultyFactor) {
|
package/dist/relay.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relay.js","sourceRoot":"","sources":["../src/relay.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"relay.js","sourceRoot":"","sources":["../src/relay.ts"],"names":[],"mappings":";;AAqDA,4CAqBC;AAmCD,8CAaC;AA0BD,8CAiBC;AAlKD,iDAA4C;AAQ5C,mCAA4E;AA0CrE,KAAK,UAAU,gBAAgB,CAClC,aAA4B,EAC5B,IAAY,EACZ,UAAoB;IAEpB,MAAM,KAAK,GAAG,MAAM,aAAa,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC1D,MAAM,EAAE,GAAG,2BAAW,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAEtC,MAAM,aAAa,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAC5C,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;IAEvC,MAAM,cAAc,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAC7C,cAAc,CAAC,YAAY,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;IAEzC,OAAO;QACH,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC;QACtC,WAAW,EAAE,IAAA,sBAAc,EAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;QAC/C,YAAY,EAAE,IAAA,uBAAe,EAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;QACjD,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC,KAAK,CAAC;QACxC,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC,IAAA,wBAAgB,EAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS;KAC/E,CAAC;AACN,CAAC;AAmCM,KAAK,UAAU,iBAAiB,CACnC,aAA4B,EAC5B,IAAY,EACZ,uBAA+B;IAE/B,MAAM,WAAW,GAAG,MAAM,aAAa,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAC7D,MAAM,cAAc,GAAG,MAAM,iBAAiB,CAAC,aAAa,EAAE,WAAW,CAAC,WAAW,EAAE,uBAAuB,CAAC,CAAC;IAEhH,OAAO;QACH,WAAW,EAAE,WAAW,CAAC,MAAM;QAC/B,cAAc,EAAE,WAAW,CAAC,GAAG;QAC/B,cAAc,EAAE,cAAc;KACjC,CAAC;AACN,CAAC;AA0BM,KAAK,UAAU,iBAAiB,CACnC,aAA4B,EAC5B,WAAmB,EACnB,SAAiB;IAEjB,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,GAAW,EAAE,EAAE,CACzC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,GAAG,KAAK,EAAE,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC;IAC5E,MAAM,YAAY,GAAG,KAAK,CAAC,WAAW,EAAE,WAAW,GAAG,SAAS,CAAC,CAAC;IAEjE,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,GAAG,CACpC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC9B,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QACtD,OAAO,aAAa,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC,CAAC,CACL,CAAC;IAEF,OAAO,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -8,42 +8,42 @@ const yargs_1 = __importDefault(require("yargs"));
|
|
|
8
8
|
const helpers_1 = require("yargs/helpers");
|
|
9
9
|
const node_child_process_1 = require("node:child_process");
|
|
10
10
|
const args = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
11
|
-
.option(
|
|
12
|
-
description:
|
|
11
|
+
.option('init-height', {
|
|
12
|
+
description: 'Height of the bitcoin chain to initialize the relay at',
|
|
13
13
|
demandOption: true,
|
|
14
14
|
})
|
|
15
|
-
.option(
|
|
16
|
-
description:
|
|
17
|
-
type:
|
|
15
|
+
.option('private-key', {
|
|
16
|
+
description: 'Private key to submit with',
|
|
17
|
+
type: 'string',
|
|
18
18
|
})
|
|
19
|
-
.option(
|
|
20
|
-
description:
|
|
21
|
-
type:
|
|
19
|
+
.option('dev', {
|
|
20
|
+
description: 'Deploy the contracts locally',
|
|
21
|
+
type: 'boolean',
|
|
22
22
|
})
|
|
23
|
-
.option(
|
|
24
|
-
description:
|
|
25
|
-
type:
|
|
23
|
+
.option('testnet', {
|
|
24
|
+
description: 'Use the testnet relay contract which can override the difficulty',
|
|
25
|
+
type: 'boolean',
|
|
26
26
|
})
|
|
27
|
-
.option(
|
|
28
|
-
description:
|
|
29
|
-
type:
|
|
27
|
+
.option('proof-length', {
|
|
28
|
+
description: 'The default proof length for retargets',
|
|
29
|
+
type: 'number',
|
|
30
30
|
default: 1,
|
|
31
31
|
})
|
|
32
|
-
.option(
|
|
33
|
-
description:
|
|
34
|
-
type:
|
|
32
|
+
.option('network', {
|
|
33
|
+
description: 'Bitcoin network to use',
|
|
34
|
+
type: 'string',
|
|
35
35
|
demandOption: true,
|
|
36
36
|
})
|
|
37
|
-
.option(
|
|
38
|
-
description:
|
|
39
|
-
type:
|
|
37
|
+
.option('rpc-url', {
|
|
38
|
+
description: 'ETH RPC URL',
|
|
39
|
+
type: 'string',
|
|
40
40
|
})
|
|
41
|
-
.option(
|
|
42
|
-
description:
|
|
43
|
-
type:
|
|
41
|
+
.option('verifier-url', {
|
|
42
|
+
description: 'Verifier URL',
|
|
43
|
+
type: 'string',
|
|
44
44
|
}).argv;
|
|
45
45
|
main().catch((err) => {
|
|
46
|
-
console.log(
|
|
46
|
+
console.log('Error thrown by script:');
|
|
47
47
|
console.log(err);
|
|
48
48
|
process.exit(1);
|
|
49
49
|
});
|
|
@@ -53,62 +53,62 @@ function range(size, startAt = 0) {
|
|
|
53
53
|
async function getRetargetHeaders(esploraClient, nextRetargetHeight, proofLength) {
|
|
54
54
|
const beforeRetarget = await Promise.all(range(proofLength, nextRetargetHeight - proofLength).map((height) => esploraClient.getBlockHeaderAt(height)));
|
|
55
55
|
const afterRetarget = await Promise.all(range(proofLength, nextRetargetHeight).map((height) => esploraClient.getBlockHeaderAt(height)));
|
|
56
|
-
return beforeRetarget.concat(afterRetarget).join(
|
|
56
|
+
return beforeRetarget.concat(afterRetarget).join('');
|
|
57
57
|
}
|
|
58
58
|
async function main() {
|
|
59
|
-
const esploraClient = new esplora_1.EsploraClient(args[
|
|
60
|
-
let initHeight = args[
|
|
61
|
-
if (initHeight ==
|
|
59
|
+
const esploraClient = new esplora_1.EsploraClient(args['network']);
|
|
60
|
+
let initHeight = args['init-height'];
|
|
61
|
+
if (initHeight == 'latest') {
|
|
62
62
|
const currentHeight = await esploraClient.getLatestHeight();
|
|
63
63
|
initHeight = currentHeight - (currentHeight % 2016) - 2016;
|
|
64
64
|
console.log(`Using block ${initHeight}`);
|
|
65
65
|
}
|
|
66
66
|
if (initHeight % 2016 != 0) {
|
|
67
|
-
throw new Error(
|
|
67
|
+
throw new Error('Invalid genesis height: must be multiple of 2016');
|
|
68
68
|
}
|
|
69
69
|
const genesis = await esploraClient.getBlockHeaderAt(initHeight);
|
|
70
|
-
const proofLength = args[
|
|
70
|
+
const proofLength = args['proof-length'];
|
|
71
71
|
const nextRetargetHeight = initHeight + 2016;
|
|
72
72
|
console.log(`Next retarget height: ${nextRetargetHeight}`);
|
|
73
73
|
const retargetHeaders = await getRetargetHeaders(esploraClient, nextRetargetHeight, proofLength);
|
|
74
74
|
let rpcUrl;
|
|
75
75
|
let verifyOpts;
|
|
76
|
-
if (args[
|
|
77
|
-
rpcUrl =
|
|
76
|
+
if (args['dev']) {
|
|
77
|
+
rpcUrl = 'http://localhost:8545';
|
|
78
78
|
}
|
|
79
|
-
else if (args[
|
|
80
|
-
rpcUrl =
|
|
79
|
+
else if (args['rpc-url'] == 'testnet') {
|
|
80
|
+
rpcUrl = 'https://bob-sepolia.rpc.gobob.xyz/';
|
|
81
81
|
verifyOpts = "--verify --verifier blockscout --verifier-url 'https://bob-sepolia.explorer.gobob.xyz/api'";
|
|
82
82
|
}
|
|
83
|
-
else if (args[
|
|
84
|
-
rpcUrl =
|
|
83
|
+
else if (args['rpc-url'] == 'mainnet') {
|
|
84
|
+
rpcUrl = 'https://rpc.gobob.xyz/';
|
|
85
85
|
verifyOpts = "--verify --verifier blockscout --verifier-url 'https://explorer.gobob.xyz/api'";
|
|
86
86
|
}
|
|
87
87
|
else {
|
|
88
|
-
rpcUrl = args[
|
|
89
|
-
verifyOpts = `--verify --verifier blockscout --verifier-url ${args[
|
|
88
|
+
rpcUrl = args['rpc-url'];
|
|
89
|
+
verifyOpts = `--verify --verifier blockscout --verifier-url ${args['verifier-url']}`;
|
|
90
90
|
}
|
|
91
91
|
let privateKey;
|
|
92
|
-
if (args[
|
|
93
|
-
privateKey = args[
|
|
92
|
+
if (args['private-key']) {
|
|
93
|
+
privateKey = args['private-key'];
|
|
94
94
|
}
|
|
95
|
-
else if (args[
|
|
96
|
-
privateKey =
|
|
95
|
+
else if (args['dev']) {
|
|
96
|
+
privateKey = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80';
|
|
97
97
|
}
|
|
98
98
|
else {
|
|
99
|
-
throw new Error(
|
|
99
|
+
throw new Error('No private key');
|
|
100
100
|
}
|
|
101
|
-
|
|
101
|
+
const env = [
|
|
102
102
|
`GENESIS_PROOF_LENGTH=${proofLength}`,
|
|
103
103
|
`GENESIS_HEIGHT=${initHeight}`,
|
|
104
104
|
`GENESIS_HEADER=${genesis}`,
|
|
105
105
|
`RETARGET_HEADERS=${retargetHeaders}`,
|
|
106
106
|
`PRIVATE_KEY=${privateKey}`,
|
|
107
107
|
];
|
|
108
|
-
if (args[
|
|
109
|
-
env.push(
|
|
108
|
+
if (args['testnet']) {
|
|
109
|
+
env.push('TESTNET=true');
|
|
110
110
|
}
|
|
111
|
-
(0, node_child_process_1.exec)(`${env.join(
|
|
111
|
+
(0, node_child_process_1.exec)(`${env.join(' ')} forge script ../script/RelayGenesis.s.sol:RelayGenesisScript --rpc-url '${rpcUrl}' ${verifyOpts} --broadcast --priority-gas-price 1`, { maxBuffer: 1024 * 5000 }, (err, stdout, stderr) => {
|
|
112
112
|
if (err) {
|
|
113
113
|
throw new Error(`Failed to run command: ${err}`);
|
|
114
114
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relay-genesis.js","sourceRoot":"","sources":["../../src/scripts/relay-genesis.ts"],"names":[],"mappings":";;;;;AAAA,wCAA2C;AAC3C,kDAA0B;AAC1B,2CAAwC;AACxC,2DAA0C;AAE1C,MAAM,IAAI,GAAG,IAAA,eAAK,EAAC,IAAA,iBAAO,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;KACpC,MAAM,CAAC,aAAa,EAAE;IACnB,WAAW,EAAE,wDAAwD;IACrE,YAAY,EAAE,IAAI;CACrB,CAAC;KACD,MAAM,CAAC,aAAa,EAAE;IACnB,WAAW,EAAE,4BAA4B;IACzC,IAAI,EAAE,QAAQ;CACjB,CAAC;KACD,MAAM,CAAC,KAAK,EAAE;IACX,WAAW,EAAE,8BAA8B;IAC3C,IAAI,EAAE,SAAS;CAClB,CAAC;KACD,MAAM,CAAC,SAAS,EAAE;IACf,WAAW,EAAE,kEAAkE;IAC/E,IAAI,EAAE,SAAS;CAClB,CAAC;KACD,MAAM,CAAC,cAAc,EAAE;IACpB,WAAW,EAAE,wCAAwC;IACrD,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,CAAC;CACb,CAAC;KACD,MAAM,CAAC,SAAS,EAAE;IACf,WAAW,EAAE,wBAAwB;IACrC,IAAI,EAAE,QAAQ;IACd,YAAY,EAAE,IAAI;CACrB,CAAC;KACD,MAAM,CAAC,SAAS,EAAE;IACf,WAAW,EAAE,aAA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J,CAAC;AACN,CAAC"}
|
|
@@ -8,31 +8,31 @@ const yargs_1 = __importDefault(require("yargs"));
|
|
|
8
8
|
const helpers_1 = require("yargs/helpers");
|
|
9
9
|
const node_child_process_1 = require("node:child_process");
|
|
10
10
|
const args = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
11
|
-
.env(
|
|
12
|
-
.option(
|
|
13
|
-
description:
|
|
14
|
-
type:
|
|
11
|
+
.env('RELAY')
|
|
12
|
+
.option('private-key', {
|
|
13
|
+
description: 'Private key to submit with',
|
|
14
|
+
type: 'string',
|
|
15
15
|
})
|
|
16
|
-
.option(
|
|
17
|
-
description:
|
|
18
|
-
type:
|
|
16
|
+
.option('dev', {
|
|
17
|
+
description: 'Deploy the contracts locally',
|
|
18
|
+
type: 'boolean',
|
|
19
19
|
})
|
|
20
|
-
.option(
|
|
21
|
-
description:
|
|
22
|
-
type:
|
|
20
|
+
.option('network', {
|
|
21
|
+
description: 'Bitcoin network to use',
|
|
22
|
+
type: 'string',
|
|
23
23
|
demandOption: true,
|
|
24
24
|
})
|
|
25
|
-
.option(
|
|
26
|
-
description:
|
|
27
|
-
type:
|
|
25
|
+
.option('rpc-url', {
|
|
26
|
+
description: 'ETH RPC URL',
|
|
27
|
+
type: 'string',
|
|
28
28
|
})
|
|
29
|
-
.option(
|
|
30
|
-
description:
|
|
31
|
-
type:
|
|
29
|
+
.option('relay-address', {
|
|
30
|
+
description: 'Relay address',
|
|
31
|
+
type: 'string',
|
|
32
32
|
demandOption: true,
|
|
33
33
|
}).argv;
|
|
34
34
|
main().catch((err) => {
|
|
35
|
-
console.log(
|
|
35
|
+
console.log('Error thrown by script:');
|
|
36
36
|
console.log(err);
|
|
37
37
|
process.exit(1);
|
|
38
38
|
});
|
|
@@ -42,33 +42,33 @@ function range(size, startAt = 0) {
|
|
|
42
42
|
async function getRetargetHeaders(esploraClient, nextRetargetHeight, proofLength) {
|
|
43
43
|
const beforeRetarget = await Promise.all(range(proofLength, nextRetargetHeight - proofLength).map((height) => esploraClient.getBlockHeaderAt(height)));
|
|
44
44
|
const afterRetarget = await Promise.all(range(proofLength, nextRetargetHeight).map((height) => esploraClient.getBlockHeaderAt(height)));
|
|
45
|
-
return beforeRetarget.concat(afterRetarget).join(
|
|
45
|
+
return beforeRetarget.concat(afterRetarget).join('');
|
|
46
46
|
}
|
|
47
47
|
async function main() {
|
|
48
|
-
const esploraClient = new esplora_1.EsploraClient(args[
|
|
48
|
+
const esploraClient = new esplora_1.EsploraClient(args['network']);
|
|
49
49
|
let privateKey;
|
|
50
|
-
if (args[
|
|
51
|
-
privateKey = args[
|
|
50
|
+
if (args['private-key']) {
|
|
51
|
+
privateKey = args['private-key'];
|
|
52
52
|
}
|
|
53
|
-
else if (args[
|
|
54
|
-
privateKey =
|
|
53
|
+
else if (args['dev']) {
|
|
54
|
+
privateKey = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80';
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
57
|
-
throw new Error(
|
|
57
|
+
throw new Error('No private key');
|
|
58
58
|
}
|
|
59
|
-
const relayAddress = args[
|
|
59
|
+
const relayAddress = args['relay-address'];
|
|
60
60
|
let rpcUrl;
|
|
61
|
-
if (args[
|
|
62
|
-
rpcUrl =
|
|
61
|
+
if (args['dev']) {
|
|
62
|
+
rpcUrl = 'http://localhost:8545';
|
|
63
63
|
}
|
|
64
|
-
else if (args[
|
|
65
|
-
rpcUrl =
|
|
64
|
+
else if (args['rpc-url'] == 'testnet') {
|
|
65
|
+
rpcUrl = 'https://bob-sepolia.rpc.gobob.xyz/';
|
|
66
66
|
}
|
|
67
|
-
else if (args[
|
|
68
|
-
rpcUrl =
|
|
67
|
+
else if (args['rpc-url'] == 'mainnet') {
|
|
68
|
+
rpcUrl = 'https://rpc.gobob.xyz/';
|
|
69
69
|
}
|
|
70
70
|
else {
|
|
71
|
-
rpcUrl = args[
|
|
71
|
+
rpcUrl = args['rpc-url'];
|
|
72
72
|
}
|
|
73
73
|
const currentEpoch = await new Promise((resolve, reject) => {
|
|
74
74
|
(0, node_child_process_1.exec)(`cast call ${relayAddress} "currentEpoch() (uint256)" --rpc-url '${rpcUrl}'`, (err, stdout, _stderr) => {
|
|
@@ -93,7 +93,7 @@ async function main() {
|
|
|
93
93
|
try {
|
|
94
94
|
await esploraClient.getBlockHash(nextRetargetHeight + proofLength);
|
|
95
95
|
}
|
|
96
|
-
catch (
|
|
96
|
+
catch (_) {
|
|
97
97
|
console.log(`Cannot retarget without ${proofLength} headers after ${nextRetargetHeight}. Exiting.`);
|
|
98
98
|
return;
|
|
99
99
|
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Block } from
|
|
2
|
-
import { Transaction } from
|
|
1
|
+
import { Block } from 'bitcoinjs-lib';
|
|
2
|
+
import { Transaction } from 'bitcoinjs-lib/src/transaction';
|
|
3
3
|
export declare function encodeRawInput(tx: Transaction): Buffer;
|
|
4
4
|
export declare function encodeRawOutput(tx: Transaction): Buffer;
|
|
5
5
|
export declare function encodeRawWitness(tx: Transaction): Buffer;
|
package/dist/utils.js
CHANGED
|
@@ -36,13 +36,14 @@ function varSliceSize(someScript) {
|
|
|
36
36
|
return bufferutils_1.varuint.encodingLength(length) + length;
|
|
37
37
|
}
|
|
38
38
|
function encodeRawInput(tx) {
|
|
39
|
-
const inputSize = bufferutils_1.varuint.encodingLength(tx.ins.length) +
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
const inputSize = bufferutils_1.varuint.encodingLength(tx.ins.length) +
|
|
40
|
+
tx.ins.reduce((sum, input) => {
|
|
41
|
+
return sum + 40 + varSliceSize(input.script);
|
|
42
|
+
}, 0);
|
|
42
43
|
const inputBuffer = Buffer.allocUnsafe(inputSize);
|
|
43
44
|
const inputBufferWriter = new bufferutils_1.BufferWriter(inputBuffer, 0);
|
|
44
45
|
inputBufferWriter.writeVarInt(tx.ins.length);
|
|
45
|
-
tx.ins.forEach(txIn => {
|
|
46
|
+
tx.ins.forEach((txIn) => {
|
|
46
47
|
inputBufferWriter.writeSlice(txIn.hash);
|
|
47
48
|
inputBufferWriter.writeUInt32(txIn.index);
|
|
48
49
|
inputBufferWriter.writeVarSlice(txIn.script);
|
|
@@ -54,13 +55,14 @@ function isOutput(out) {
|
|
|
54
55
|
return out.value !== undefined;
|
|
55
56
|
}
|
|
56
57
|
function encodeRawOutput(tx) {
|
|
57
|
-
const outputSize = bufferutils_1.varuint.encodingLength(tx.outs.length) +
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
const outputSize = bufferutils_1.varuint.encodingLength(tx.outs.length) +
|
|
59
|
+
tx.outs.reduce((sum, output) => {
|
|
60
|
+
return sum + 8 + varSliceSize(output.script);
|
|
61
|
+
}, 0);
|
|
60
62
|
const outputBuffer = Buffer.allocUnsafe(outputSize);
|
|
61
63
|
const outputBufferWriter = new bufferutils_1.BufferWriter(outputBuffer, 0);
|
|
62
64
|
outputBufferWriter.writeVarInt(tx.outs.length);
|
|
63
|
-
tx.outs.forEach(txOut => {
|
|
65
|
+
tx.outs.forEach((txOut) => {
|
|
64
66
|
if (isOutput(txOut)) {
|
|
65
67
|
outputBufferWriter.writeUInt64(txOut.value);
|
|
66
68
|
}
|
|
@@ -84,7 +86,7 @@ function encodeRawWitness(tx) {
|
|
|
84
86
|
}, 0);
|
|
85
87
|
const witnessBuffer = Buffer.allocUnsafe(witnessSize);
|
|
86
88
|
const witnessBufferWriter = new bufferutils_1.BufferWriter(witnessBuffer, 0);
|
|
87
|
-
tx.ins.forEach(input => {
|
|
89
|
+
tx.ins.forEach((input) => {
|
|
88
90
|
witnessBufferWriter.writeVector(input.witness);
|
|
89
91
|
});
|
|
90
92
|
return witnessBuffer;
|
|
@@ -99,10 +101,10 @@ function chunkArray(array, chunkSize) {
|
|
|
99
101
|
return chunkedArray;
|
|
100
102
|
}
|
|
101
103
|
function createMerkleBranchAndRoot(hashes, index) {
|
|
102
|
-
|
|
104
|
+
const merkle = [];
|
|
103
105
|
while (hashes.length > 1) {
|
|
104
106
|
if (hashes.length % 2 != 0) {
|
|
105
|
-
|
|
107
|
+
const last = hashes[hashes.length - 1];
|
|
106
108
|
hashes.push(last);
|
|
107
109
|
}
|
|
108
110
|
if (index % 2 == 0) {
|
|
@@ -113,7 +115,7 @@ function createMerkleBranchAndRoot(hashes, index) {
|
|
|
113
115
|
}
|
|
114
116
|
merkle.push(hashes[index]);
|
|
115
117
|
index = Math.floor(index / 2);
|
|
116
|
-
hashes = chunkArray(hashes, 2).map(pair => (0, crypto_1.hash256)(Buffer.concat([pair[0], pair[1]])));
|
|
118
|
+
hashes = chunkArray(hashes, 2).map((pair) => (0, crypto_1.hash256)(Buffer.concat([pair[0], pair[1]])));
|
|
117
119
|
}
|
|
118
120
|
return {
|
|
119
121
|
merkle,
|
|
@@ -121,13 +123,13 @@ function createMerkleBranchAndRoot(hashes, index) {
|
|
|
121
123
|
};
|
|
122
124
|
}
|
|
123
125
|
function getMerkleProof(block, txHash, forWitness) {
|
|
124
|
-
const txIds = block.transactions.map(tx => tx.getHash(forWitness));
|
|
125
|
-
const pos = txIds.map(value => value.toString(
|
|
126
|
+
const txIds = block.transactions.map((tx) => tx.getHash(forWitness));
|
|
127
|
+
const pos = txIds.map((value) => value.toString('hex')).indexOf(txHash);
|
|
126
128
|
const merkleAndRoot = createMerkleBranchAndRoot(txIds, pos);
|
|
127
129
|
return {
|
|
128
130
|
pos: pos,
|
|
129
|
-
proof: merkleAndRoot.merkle.map(value => value.toString(
|
|
130
|
-
root: merkleAndRoot.root.toString(
|
|
131
|
+
proof: merkleAndRoot.merkle.map((value) => value.toString('hex')).join(''),
|
|
132
|
+
root: merkleAndRoot.root.toString('hex'),
|
|
131
133
|
};
|
|
132
134
|
}
|
|
133
135
|
function estimateTxFee(feeRate, numInputs = 1) {
|
|
@@ -135,7 +137,7 @@ function estimateTxFee(feeRate, numInputs = 1) {
|
|
|
135
137
|
for (let i = 0; i < numInputs; i++) {
|
|
136
138
|
tx.addInput(Buffer.alloc(32, 0), 0, 0xfffffffd, Buffer.alloc(0));
|
|
137
139
|
}
|
|
138
|
-
tx.ins.map(tx_input => (tx_input.witness = [Buffer.alloc(33 + 32 + 7, 0), Buffer.alloc(33, 0)]));
|
|
140
|
+
tx.ins.map((tx_input) => (tx_input.witness = [Buffer.alloc(33 + 32 + 7, 0), Buffer.alloc(33, 0)]));
|
|
139
141
|
tx.addOutput(Buffer.alloc(22, 0), 1000);
|
|
140
142
|
tx.addOutput(Buffer.alloc(22, 0), 1000);
|
|
141
143
|
tx.addOutput(bitcoin.script.compile([bitcoin.opcodes.OP_RETURN, Buffer.alloc(20, 0)]), 0);
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,wCAmBC;AAYD,0CAuBC;AAmBD,4CAaC;AA2DD,wCAWC;AASD,sCAaC;AA3MD,+DAAsE;AAItE,qDAAmD;AAQnD,uDAAyC;AAKzC,SAAS,YAAY,CAAC,UAAkB;IACpC,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IACjC,OAAO,qBAAO,CAAC,cAAc,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;AACnD,CAAC;AAKD,SAAgB,cAAc,CAAC,EAAe;IAC1C,MAAM,SAAS,GACX,qBAAO,CAAC,cAAc,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC;QACrC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YACzB,OAAO,GAAG,GAAG,EAAE,GAAG,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACjD,CAAC,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AAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,OAAO,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACnG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IACxC,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IACxC,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1F,MAAM,KAAK,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC;IAC/B,MAAM,QAAQ,GAAG,OAAO,GAAG,KAAK,CAAC;IACjC,OAAO,QAAQ,CAAC;AACpB,CAAC"}
|
package/dist/wallet/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export { validate as isValidBtcAddress } from
|
|
1
|
+
export * from './utxo';
|
|
2
|
+
export { validate as isValidBtcAddress } from 'bitcoin-address-validation';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EsploraClient, UTXO } from
|
|
2
|
-
import { OrdinalsClient } from
|
|
1
|
+
import { EsploraClient, UTXO } from '../esplora';
|
|
2
|
+
import { OrdinalsClient } from '../ordinal-api';
|
|
3
3
|
export declare function findUtxoForInscriptionId(esploraClient: EsploraClient, ordinalsClient: OrdinalsClient, utxos: UTXO[], inscriptionId: string): Promise<UTXO | undefined>;
|
|
4
4
|
export declare function findUtxosWithoutInscriptions(network: string, utxos: UTXO[]): Promise<UTXO[]>;
|
|
@@ -15,7 +15,7 @@ async function findUtxoForInscriptionId(esploraClient, ordinalsClient, utxos, in
|
|
|
15
15
|
}
|
|
16
16
|
else if (txid == utxo.txid) {
|
|
17
17
|
const inscriptions = await (0, inscription_1.getTxInscriptions)(esploraClient, utxo.txid);
|
|
18
|
-
if (typeof inscriptions[index] !==
|
|
18
|
+
if (typeof inscriptions[index] !== 'undefined') {
|
|
19
19
|
return utxo;
|
|
20
20
|
}
|
|
21
21
|
}
|
package/dist/wallet/utxo.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Transaction } from
|
|
2
|
-
import { AddressType, Network } from
|
|
3
|
-
import { UTXO } from
|
|
4
|
-
export type BitcoinNetworkName = Exclude<Network,
|
|
1
|
+
import { Transaction } from '@scure/btc-signer';
|
|
2
|
+
import { AddressType, Network } from 'bitcoin-address-validation';
|
|
3
|
+
import { UTXO } from '../esplora';
|
|
4
|
+
export type BitcoinNetworkName = Exclude<Network, 'regtest'>;
|
|
5
5
|
export declare const getBtcNetwork: (name: BitcoinNetworkName) => {
|
|
6
6
|
bech32: string;
|
|
7
7
|
pubKeyHash: number;
|
package/dist/wallet/utxo.js
CHANGED
|
@@ -18,12 +18,12 @@ exports.getBtcNetwork = getBtcNetwork;
|
|
|
18
18
|
async function createBitcoinPsbt(fromAddress, toAddress, amount, publicKey, opReturnData, confirmationTarget = 3) {
|
|
19
19
|
const addressInfo = (0, bitcoin_address_validation_1.getAddressInfo)(fromAddress);
|
|
20
20
|
const network = addressInfo.network;
|
|
21
|
-
if (network ===
|
|
22
|
-
throw new Error(
|
|
21
|
+
if (network === 'regtest') {
|
|
22
|
+
throw new Error('Bitcoin regtest not supported');
|
|
23
23
|
}
|
|
24
24
|
if (addressInfo.type === (bitcoin_address_validation_1.AddressType.p2sh || bitcoin_address_validation_1.AddressType.p2wsh)) {
|
|
25
25
|
if (!publicKey) {
|
|
26
|
-
throw new Error(
|
|
26
|
+
throw new Error('Public key is required to spend from the selected address type');
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
const esploraClient = new esplora_1.EsploraClient(addressInfo.network);
|
|
@@ -32,12 +32,12 @@ async function createBitcoinPsbt(fromAddress, toAddress, amount, publicKey, opRe
|
|
|
32
32
|
esploraClient.getFeeEstimate(confirmationTarget),
|
|
33
33
|
]);
|
|
34
34
|
if (confirmedUtxos.length === 0) {
|
|
35
|
-
throw new Error(
|
|
35
|
+
throw new Error('No confirmed UTXOs');
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
const possibleInputs = [];
|
|
38
38
|
await Promise.all(confirmedUtxos.map(async (utxo) => {
|
|
39
39
|
const hex = await esploraClient.getTransactionHex(utxo.txid);
|
|
40
|
-
const transaction = btc_signer_1.Transaction.fromRaw(Buffer.from(hex,
|
|
40
|
+
const transaction = btc_signer_1.Transaction.fromRaw(Buffer.from(hex, 'hex'), { allowUnknownOutputs: true });
|
|
41
41
|
const input = getInputFromUtxoAndTx(network, utxo, transaction, addressInfo.type, publicKey);
|
|
42
42
|
possibleInputs.push(input);
|
|
43
43
|
}));
|
|
@@ -48,15 +48,15 @@ async function createBitcoinPsbt(fromAddress, toAddress, amount, publicKey, opRe
|
|
|
48
48
|
},
|
|
49
49
|
];
|
|
50
50
|
if (opReturnData) {
|
|
51
|
-
if (opReturnData.startsWith(
|
|
51
|
+
if (opReturnData.startsWith('0x')) {
|
|
52
52
|
opReturnData = opReturnData.slice(2);
|
|
53
53
|
}
|
|
54
54
|
outputs.push({
|
|
55
|
-
script: btc_signer_1.Script.encode([
|
|
55
|
+
script: btc_signer_1.Script.encode(['RETURN', base_1.hex.decode(opReturnData)]),
|
|
56
56
|
amount: BigInt(0),
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
|
-
const transaction = (0, btc_signer_1.selectUTXO)(possibleInputs, outputs,
|
|
59
|
+
const transaction = (0, btc_signer_1.selectUTXO)(possibleInputs, outputs, 'default', {
|
|
60
60
|
changeAddress: fromAddress,
|
|
61
61
|
feePerByte: BigInt(Math.ceil(feeRate)),
|
|
62
62
|
bip69: true,
|
|
@@ -67,7 +67,7 @@ async function createBitcoinPsbt(fromAddress, toAddress, amount, publicKey, opRe
|
|
|
67
67
|
dust: BigInt(546),
|
|
68
68
|
});
|
|
69
69
|
if (!transaction || !transaction.tx) {
|
|
70
|
-
throw new Error(
|
|
70
|
+
throw new Error('Failed to create transaction. Do you have enough funds?');
|
|
71
71
|
}
|
|
72
72
|
return base_1.base64.encode(transaction.tx.toPSBT(0));
|
|
73
73
|
}
|
|
@@ -76,16 +76,16 @@ function getInputFromUtxoAndTx(network, utxo, transaction, addressType, publicKe
|
|
|
76
76
|
let redeemScript = {};
|
|
77
77
|
if (addressType === bitcoin_address_validation_1.AddressType.p2sh) {
|
|
78
78
|
if (!publicKey) {
|
|
79
|
-
throw new Error(
|
|
79
|
+
throw new Error('Bitcoin P2SH not supported without public key');
|
|
80
80
|
}
|
|
81
|
-
const inner = (0, btc_signer_1.p2wpkh)(Buffer.from(publicKey,
|
|
81
|
+
const inner = (0, btc_signer_1.p2wpkh)(Buffer.from(publicKey, 'hex'), (0, exports.getBtcNetwork)(network));
|
|
82
82
|
redeemScript = (0, btc_signer_1.p2sh)(inner);
|
|
83
83
|
}
|
|
84
84
|
const scriptMixin = {
|
|
85
85
|
...redeemScript,
|
|
86
86
|
};
|
|
87
87
|
const nonWitnessUtxo = {
|
|
88
|
-
nonWitnessUtxo: Buffer.from(transaction.hex,
|
|
88
|
+
nonWitnessUtxo: Buffer.from(transaction.hex, 'hex'),
|
|
89
89
|
};
|
|
90
90
|
const witnessUtxo = {
|
|
91
91
|
witnessUtxo: {
|