@gobob/bob-sdk 1.0.3 → 1.1.1
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/electrs.d.ts +17 -3
- package/dist/electrs.js +32 -3
- package/dist/electrs.js.map +1 -1
- package/dist/helpers.d.ts +3 -0
- package/dist/helpers.js +66 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/inscription.d.ts +17 -0
- package/dist/inscription.js +123 -0
- package/dist/inscription.js.map +1 -0
- package/dist/ordinal-api/index.d.ts +97 -0
- package/dist/ordinal-api/index.js +111 -0
- package/dist/ordinal-api/index.js.map +1 -0
- package/dist/ordinals/commit.d.ts +20 -0
- package/dist/ordinals/commit.js +98 -0
- package/dist/ordinals/commit.js.map +1 -0
- package/dist/ordinals/index.d.ts +5 -0
- package/dist/ordinals/index.js +76 -0
- package/dist/ordinals/index.js.map +1 -0
- package/dist/ordinals/reveal.d.ts +14 -0
- package/dist/ordinals/reveal.js +68 -0
- package/dist/ordinals/reveal.js.map +1 -0
- package/dist/ordinals/signer.d.ts +15 -0
- package/dist/ordinals/signer.js +17 -0
- package/dist/ordinals/signer.js.map +1 -0
- package/dist/relay.d.ts +3 -1
- package/dist/relay.js +17 -10
- package/dist/relay.js.map +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +7 -3
package/dist/electrs.d.ts
CHANGED
|
@@ -1,24 +1,38 @@
|
|
|
1
|
-
export declare const MAINNET_ESPLORA_BASE_PATH = "https://btc-mainnet.
|
|
2
|
-
export declare const TESTNET_ESPLORA_BASE_PATH = "https://btc-testnet.
|
|
3
|
-
export declare const REGTEST_ESPLORA_BASE_PATH = "http://localhost:
|
|
1
|
+
export declare const MAINNET_ESPLORA_BASE_PATH = "https://btc-mainnet.gobob.xyz";
|
|
2
|
+
export declare const TESTNET_ESPLORA_BASE_PATH = "https://btc-testnet.gobob.xyz";
|
|
3
|
+
export declare const REGTEST_ESPLORA_BASE_PATH = "http://localhost:3003";
|
|
4
4
|
export interface MerkleProof {
|
|
5
5
|
blockHeight: number;
|
|
6
6
|
merkle: string;
|
|
7
7
|
pos: number;
|
|
8
8
|
}
|
|
9
|
+
export interface UTXO {
|
|
10
|
+
txid: string;
|
|
11
|
+
vout: number;
|
|
12
|
+
value: number;
|
|
13
|
+
confirmed: boolean;
|
|
14
|
+
height?: number;
|
|
15
|
+
}
|
|
9
16
|
export interface ElectrsClient {
|
|
10
17
|
getBlockHash(height: number): Promise<string>;
|
|
11
18
|
getBlockHeader(hash: string): Promise<string>;
|
|
12
19
|
getTransactionHex(txId: string): Promise<string>;
|
|
13
20
|
getMerkleProof(txId: string): Promise<MerkleProof>;
|
|
21
|
+
getFeeEstimate(confirmationTarget: number): Promise<number>;
|
|
22
|
+
getAddressUtxos(address: string): Promise<Array<UTXO>>;
|
|
23
|
+
broadcastTx(txHex: string): Promise<string>;
|
|
14
24
|
}
|
|
15
25
|
export declare class DefaultElectrsClient implements ElectrsClient {
|
|
16
26
|
private basePath;
|
|
17
27
|
constructor(networkOrUrl?: string);
|
|
18
28
|
getBlockHash(height: number): Promise<string>;
|
|
19
29
|
getBlockHeader(hash: string): Promise<string>;
|
|
30
|
+
getBlockHeaderAt(height: number): Promise<string>;
|
|
20
31
|
getTransactionHex(txId: string): Promise<string>;
|
|
21
32
|
getMerkleProof(txId: string): Promise<MerkleProof>;
|
|
33
|
+
getFeeEstimate(confirmationTarget: number): Promise<number>;
|
|
34
|
+
getAddressUtxos(address: string, confirmed?: boolean): Promise<Array<UTXO>>;
|
|
35
|
+
broadcastTx(txHex: string): Promise<string>;
|
|
22
36
|
getJson<T>(url: string): Promise<T>;
|
|
23
37
|
getText(url: string): Promise<string>;
|
|
24
38
|
}
|
package/dist/electrs.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DefaultElectrsClient = exports.REGTEST_ESPLORA_BASE_PATH = exports.TESTNET_ESPLORA_BASE_PATH = exports.MAINNET_ESPLORA_BASE_PATH = void 0;
|
|
4
|
-
exports.MAINNET_ESPLORA_BASE_PATH = "https://btc-mainnet.
|
|
5
|
-
exports.TESTNET_ESPLORA_BASE_PATH = "https://btc-testnet.
|
|
6
|
-
exports.REGTEST_ESPLORA_BASE_PATH = "http://localhost:
|
|
4
|
+
exports.MAINNET_ESPLORA_BASE_PATH = "https://btc-mainnet.gobob.xyz";
|
|
5
|
+
exports.TESTNET_ESPLORA_BASE_PATH = "https://btc-testnet.gobob.xyz";
|
|
6
|
+
exports.REGTEST_ESPLORA_BASE_PATH = "http://localhost:3003";
|
|
7
7
|
function encodeElectrsMerkleProof(merkle) {
|
|
8
8
|
return merkle.map(item => Buffer.from(item, "hex").reverse().toString("hex")).join('');
|
|
9
9
|
}
|
|
@@ -29,6 +29,10 @@ class DefaultElectrsClient {
|
|
|
29
29
|
async getBlockHeader(hash) {
|
|
30
30
|
return this.getText(`${this.basePath}/block/${hash}/header`);
|
|
31
31
|
}
|
|
32
|
+
async getBlockHeaderAt(height) {
|
|
33
|
+
const blockHash = await this.getBlockHash(height);
|
|
34
|
+
return await this.getBlockHeader(blockHash);
|
|
35
|
+
}
|
|
32
36
|
async getTransactionHex(txId) {
|
|
33
37
|
return this.getText(`${this.basePath}/tx/${txId}/hex`);
|
|
34
38
|
}
|
|
@@ -40,6 +44,31 @@ class DefaultElectrsClient {
|
|
|
40
44
|
pos: response.pos,
|
|
41
45
|
};
|
|
42
46
|
}
|
|
47
|
+
async getFeeEstimate(confirmationTarget) {
|
|
48
|
+
const response = await this.getJson(`${this.basePath}/fee-estimates`);
|
|
49
|
+
return response[confirmationTarget];
|
|
50
|
+
}
|
|
51
|
+
async getAddressUtxos(address, confirmed) {
|
|
52
|
+
const response = await this.getJson(`${this.basePath}/address/${address}/utxo`);
|
|
53
|
+
return response
|
|
54
|
+
.filter(utxo => (typeof confirmed !== "undefined") ? confirmed === utxo.status.confirmed : true)
|
|
55
|
+
.map(utxo => {
|
|
56
|
+
return {
|
|
57
|
+
txid: utxo.txid,
|
|
58
|
+
vout: utxo.vout,
|
|
59
|
+
value: utxo.value,
|
|
60
|
+
confirmed: utxo.status.confirmed,
|
|
61
|
+
height: utxo.status.block_height
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
async broadcastTx(txHex) {
|
|
66
|
+
const res = await fetch(`${this.basePath}/tx`, {
|
|
67
|
+
method: 'POST',
|
|
68
|
+
body: txHex
|
|
69
|
+
});
|
|
70
|
+
return await res.text();
|
|
71
|
+
}
|
|
43
72
|
async getJson(url) {
|
|
44
73
|
const response = await fetch(url);
|
|
45
74
|
if (!response.ok) {
|
package/dist/electrs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"electrs.js","sourceRoot":"","sources":["../src/electrs.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"electrs.js","sourceRoot":"","sources":["../src/electrs.ts"],"names":[],"mappings":";;;AAIa,QAAA,yBAAyB,GAAG,+BAA+B,CAAC;AAK5D,QAAA,yBAAyB,GAAG,+BAA+B,CAAC;AAK5D,QAAA,yBAAyB,GAAG,uBAAuB,CAAC;AA6IjE,SAAS,wBAAwB,CAAC,MAAgB;IAE9C,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC3F,CAAC;AAMD,MAAa,oBAAoB;IAmB7B,YAAY,eAAuB,SAAS;QACxC,QAAQ,YAAY,EAAE,CAAC;YACnB,KAAK,SAAS;gBACV,IAAI,CAAC,QAAQ,GAAG,iCAAyB,CAAC;gBAC1C,MAAM;YACV,KA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MAAM,QAAQ,CAAC,IAAI,EAAgB,CAAC;IAC/C,CAAC;IAKD,KAAK,CAAC,OAAO,CAAC,GAAW;QACrB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACjC,CAAC;CACJ;AApJD,oDAoJC"}
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getInscriptionIds = void 0;
|
|
27
|
+
const inscription_1 = require("./inscription");
|
|
28
|
+
const ordinal_api_1 = require("./ordinal-api");
|
|
29
|
+
const bitcoin = __importStar(require("bitcoinjs-lib"));
|
|
30
|
+
async function getInscriptionIds(electrsClient, ordinalsClient, bitcoinAddress) {
|
|
31
|
+
const utxos = await electrsClient.getAddressUtxos(bitcoinAddress);
|
|
32
|
+
const inscriptionIds = await Promise.all(utxos.sort((a, b) => {
|
|
33
|
+
const heightA = a.height || Number.MAX_SAFE_INTEGER;
|
|
34
|
+
const heightB = b.height || Number.MAX_SAFE_INTEGER;
|
|
35
|
+
return heightA - heightB;
|
|
36
|
+
}).map(utxo => getInscriptionIdsForUtxo(electrsClient, ordinalsClient, utxo)));
|
|
37
|
+
return inscriptionIds.flat();
|
|
38
|
+
}
|
|
39
|
+
exports.getInscriptionIds = getInscriptionIds;
|
|
40
|
+
async function getInscriptionIdsForUtxo(electrsClient, ordinalsClient, utxo) {
|
|
41
|
+
if (utxo.confirmed) {
|
|
42
|
+
const outputJson = await ordinalsClient.getInscriptionsFromOutPoint(utxo);
|
|
43
|
+
return outputJson.inscriptions;
|
|
44
|
+
}
|
|
45
|
+
const txHex = await electrsClient.getTransactionHex(utxo.txid);
|
|
46
|
+
const tx = bitcoin.Transaction.fromHex(txHex);
|
|
47
|
+
if (utxo.vout == 0) {
|
|
48
|
+
const parentInscriptions = await Promise.all(tx.ins.map(async (txInput) => {
|
|
49
|
+
const txid = txInput.hash.reverse().toString("hex");
|
|
50
|
+
const outputJson = await ordinalsClient.getInscriptionsFromOutPoint({ txid, vout: txInput.index });
|
|
51
|
+
return outputJson.inscriptions;
|
|
52
|
+
}));
|
|
53
|
+
const inscriptionIds = parentInscriptions.flat();
|
|
54
|
+
if (inscriptionIds.length > 0) {
|
|
55
|
+
return inscriptionIds;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const inscriptions = (0, inscription_1.parseInscriptions)(tx);
|
|
59
|
+
if (utxo.vout != 0) {
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return inscriptions.map((_, index) => ordinal_api_1.InscriptionId.toString({ txid: utxo.txid, index }));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+CAAkD;AAClD,+CAA8D;AAC9D,uDAAyC;AAGlC,KAAK,UAAU,iBAAiB,CAAC,aAA4B,EAAE,cAA8B,EAAE,cAAsB;IACxH,MAAM,KAAK,GAAG,MAAM,aAAa,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;IAClE,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,GAAG,CACpC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAEhB,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,gBAAgB,CAAC;QACpD,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,gBAAgB,CAAC;QAEpD,OAAO,OAAO,GAAG,OAAO,CAAC;IAC7B,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,wBAAwB,CAAC,aAAa,EAAE,cAAc,EAAE,IAAI,CAAC,CAAC,CAChF,CAAC;IACF,OAAO,cAAc,CAAC,IAAI,EAAE,CAAC;AACjC,CAAC;AAZD,8CAYC;AAGD,KAAK,UAAU,wBAAwB,CAAC,aAA4B,EAAE,cAA8B,EAAE,IAAU;IAC5G,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;QAEjB,MAAM,UAAU,GAAG,MAAM,cAAc,CAAC,2BAA2B,CAAC,IAAI,CAAC,CAAC;QAC1E,O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.js
CHANGED
|
@@ -17,4 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./electrs"), exports);
|
|
18
18
|
__exportStar(require("./relay"), exports);
|
|
19
19
|
__exportStar(require("./utils"), exports);
|
|
20
|
+
__exportStar(require("./ordinals"), exports);
|
|
21
|
+
__exportStar(require("./helpers"), exports);
|
|
20
22
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,0CAAwB;AACxB,0CAAwB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,0CAAwB;AACxB,0CAAwB;AACxB,6CAA2B;AAC3B,4CAA0B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as bitcoin from "bitcoinjs-lib";
|
|
3
|
+
import { ElectrsClient } from "./electrs";
|
|
4
|
+
export declare const PROTOCOL_ID: Buffer;
|
|
5
|
+
interface Tags {
|
|
6
|
+
[key: number]: Buffer | null;
|
|
7
|
+
}
|
|
8
|
+
interface Inscription {
|
|
9
|
+
tags: Tags;
|
|
10
|
+
body: Buffer[];
|
|
11
|
+
}
|
|
12
|
+
export declare function getContentType(inscription: Inscription): string | null;
|
|
13
|
+
export declare function getContentEncoding(inscription: Inscription): string | null;
|
|
14
|
+
export declare function parseInscriptions(tx: bitcoin.Transaction): Inscription[];
|
|
15
|
+
export declare function getTxInscriptions(electrsClient: ElectrsClient, txid: string): Promise<Inscription[]>;
|
|
16
|
+
export declare function getInscriptionFromId(electrsClient: ElectrsClient, inscriptionId: string): Promise<Inscription>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getInscriptionFromId = exports.getTxInscriptions = exports.parseInscriptions = exports.getContentEncoding = exports.getContentType = exports.PROTOCOL_ID = void 0;
|
|
27
|
+
const bitcoin = __importStar(require("bitcoinjs-lib"));
|
|
28
|
+
const ordinal_api_1 = require("./ordinal-api");
|
|
29
|
+
const TAPROOT_ANNEX_PREFIX = 0x50;
|
|
30
|
+
exports.PROTOCOL_ID = Buffer.from("6f7264", "hex");
|
|
31
|
+
const CONTENT_TYPE_TAG = bitcoin.opcodes.OP_1;
|
|
32
|
+
const CONTENT_ENCODING_TAG = bitcoin.opcodes.OP_9;
|
|
33
|
+
function getTapscript(witness) {
|
|
34
|
+
const len = witness.length;
|
|
35
|
+
const last = witness[len - 1];
|
|
36
|
+
if (typeof last === 'undefined') {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
let scriptPosFromLast = 2;
|
|
40
|
+
if (len >= 2 && last[0] == TAPROOT_ANNEX_PREFIX) {
|
|
41
|
+
scriptPosFromLast = 3;
|
|
42
|
+
}
|
|
43
|
+
if (typeof witness[len - scriptPosFromLast] === 'undefined') {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return bitcoin.script.decompile(witness[len - scriptPosFromLast]);
|
|
47
|
+
}
|
|
48
|
+
;
|
|
49
|
+
function getContentType(inscription) {
|
|
50
|
+
const data = inscription.tags[CONTENT_TYPE_TAG];
|
|
51
|
+
if (Buffer.isBuffer(data)) {
|
|
52
|
+
return data.toString("utf-8");
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
exports.getContentType = getContentType;
|
|
57
|
+
function getContentEncoding(inscription) {
|
|
58
|
+
const data = inscription.tags[CONTENT_ENCODING_TAG];
|
|
59
|
+
if (Buffer.isBuffer(data)) {
|
|
60
|
+
return data.toString("utf-8");
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
exports.getContentEncoding = getContentEncoding;
|
|
65
|
+
function parseInscriptions(tx) {
|
|
66
|
+
let inscriptions = [];
|
|
67
|
+
for (const txInput of tx.ins) {
|
|
68
|
+
const tapscript = getTapscript(txInput.witness);
|
|
69
|
+
if (tapscript == null) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const chunks = tapscript.values();
|
|
73
|
+
for (let chunk = chunks.next(); !chunk.done; chunk = chunks.next()) {
|
|
74
|
+
if (chunk.value != bitcoin.opcodes.OP_FALSE) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (chunks.next().value != bitcoin.opcodes.OP_IF) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const data = chunks.next().value;
|
|
81
|
+
if (!Buffer.isBuffer(data) && !data.equals(exports.PROTOCOL_ID)) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
let tags = {};
|
|
85
|
+
let body = [];
|
|
86
|
+
let isBody = false;
|
|
87
|
+
for (let chunk = chunks.next(); !chunk.done; chunk = chunks.next()) {
|
|
88
|
+
if (chunk.value == bitcoin.opcodes.OP_ENDIF) {
|
|
89
|
+
inscriptions.push({ tags, body });
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
else if (chunk.value == bitcoin.opcodes.OP_0) {
|
|
93
|
+
isBody = true;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (!isBody) {
|
|
97
|
+
const data = chunks.next().value;
|
|
98
|
+
if (typeof chunk.value == 'number' && Buffer.isBuffer(data)) {
|
|
99
|
+
tags[chunk.value] = data;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else if (Buffer.isBuffer(chunk.value)) {
|
|
103
|
+
body.push(chunk.value);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return inscriptions;
|
|
109
|
+
}
|
|
110
|
+
exports.parseInscriptions = parseInscriptions;
|
|
111
|
+
async function getTxInscriptions(electrsClient, txid) {
|
|
112
|
+
const txHex = await electrsClient.getTransactionHex(txid);
|
|
113
|
+
const tx = bitcoin.Transaction.fromHex(txHex);
|
|
114
|
+
return parseInscriptions(tx);
|
|
115
|
+
}
|
|
116
|
+
exports.getTxInscriptions = getTxInscriptions;
|
|
117
|
+
async function getInscriptionFromId(electrsClient, inscriptionId) {
|
|
118
|
+
const { txid, index } = ordinal_api_1.InscriptionId.fromString(inscriptionId);
|
|
119
|
+
const inscriptions = await getTxInscriptions(electrsClient, txid);
|
|
120
|
+
return inscriptions[index];
|
|
121
|
+
}
|
|
122
|
+
exports.getInscriptionFromId = getInscriptionF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AK,GAAG,MAAM,aAAa,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC1D,MAAM,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9C,OAAO,iBAAiB,CAAC,EAAE,CAAC,CAAC;AACjC,CAAC;AAJD,8CAIC;AAEM,KAAK,UAAU,oBAAoB,CAAC,aAA4B,EAAE,aAAqB;IAC1F,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,2BAAa,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IAChE,MAAM,YAAY,GAAG,MAAM,iBAAiB,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;IAClE,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAJD,oDAIC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export declare const REGTEST_ORD_BASE_PATH = "http://0.0.0.0:3003";
|
|
2
|
+
export declare const MAINNET_ORD_BASE_PATH = "https://ordinals-mainnet.gobob.xyz";
|
|
3
|
+
export declare const TESTNET_ORD_BASE_PATH = "https://ordinals-testnet.gobob.xyz";
|
|
4
|
+
export type InscriptionId = {
|
|
5
|
+
txid: string;
|
|
6
|
+
index: number;
|
|
7
|
+
};
|
|
8
|
+
export declare namespace InscriptionId {
|
|
9
|
+
function toString(id: InscriptionId): string;
|
|
10
|
+
function fromString(id: string): InscriptionId;
|
|
11
|
+
}
|
|
12
|
+
export type OutPoint = {
|
|
13
|
+
txid: string;
|
|
14
|
+
vout: number;
|
|
15
|
+
};
|
|
16
|
+
export declare namespace OutPoint {
|
|
17
|
+
function toString(id: OutPoint): string;
|
|
18
|
+
function fromString(id: string): OutPoint;
|
|
19
|
+
}
|
|
20
|
+
export type SatPoint = {
|
|
21
|
+
outpoint: OutPoint;
|
|
22
|
+
offset: number;
|
|
23
|
+
};
|
|
24
|
+
export declare namespace SatPoint {
|
|
25
|
+
function toString(id: SatPoint): string;
|
|
26
|
+
function fromString(id: string): SatPoint;
|
|
27
|
+
}
|
|
28
|
+
export interface InscriptionsJson<InscriptionId> {
|
|
29
|
+
inscriptions: InscriptionId[];
|
|
30
|
+
prev: number | null;
|
|
31
|
+
next: number | null;
|
|
32
|
+
lowest: number | null;
|
|
33
|
+
highest: number | null;
|
|
34
|
+
}
|
|
35
|
+
export interface OutputJson {
|
|
36
|
+
value: number;
|
|
37
|
+
script_pubkey: string;
|
|
38
|
+
address: string | null;
|
|
39
|
+
transaction: string;
|
|
40
|
+
sat_ranges: string | null;
|
|
41
|
+
inscriptions: string[];
|
|
42
|
+
runes: Record<string, number>;
|
|
43
|
+
}
|
|
44
|
+
export interface SatJson<InscriptionId> {
|
|
45
|
+
number: number;
|
|
46
|
+
decimal: string;
|
|
47
|
+
degree: string;
|
|
48
|
+
name: string;
|
|
49
|
+
block: number;
|
|
50
|
+
cycle: number;
|
|
51
|
+
epoch: number;
|
|
52
|
+
period: number;
|
|
53
|
+
offset: number;
|
|
54
|
+
rarity: string;
|
|
55
|
+
percentile: string;
|
|
56
|
+
satpoint: string | null;
|
|
57
|
+
timestamp: number;
|
|
58
|
+
inscriptions: InscriptionId[];
|
|
59
|
+
}
|
|
60
|
+
export interface InscriptionJson<InscriptionId, SatPoint> {
|
|
61
|
+
address: string | null;
|
|
62
|
+
children: InscriptionId[];
|
|
63
|
+
content_length: number | null;
|
|
64
|
+
content_type: string | null;
|
|
65
|
+
genesis_fee: number;
|
|
66
|
+
genesis_height: number;
|
|
67
|
+
inscription_id: InscriptionId;
|
|
68
|
+
inscription_number: number;
|
|
69
|
+
next: InscriptionId | null;
|
|
70
|
+
output_value: number | null;
|
|
71
|
+
parent: InscriptionId | null;
|
|
72
|
+
previous: InscriptionId | null;
|
|
73
|
+
rune: string | null;
|
|
74
|
+
sat: string | null;
|
|
75
|
+
satpoint: SatPoint;
|
|
76
|
+
timestamp: number;
|
|
77
|
+
}
|
|
78
|
+
export interface OrdinalsClient {
|
|
79
|
+
getInscriptionFromId(id: InscriptionId): Promise<InscriptionJson<InscriptionId, SatPoint>>;
|
|
80
|
+
getInscriptions(): Promise<InscriptionsJson<InscriptionId>>;
|
|
81
|
+
getInscriptionsFromBlock(height: number): Promise<InscriptionsJson<InscriptionId>>;
|
|
82
|
+
getInscriptionsFromOutPoint(outPoint: OutPoint): Promise<OutputJson>;
|
|
83
|
+
getInscriptionsFromSat(sat: number): Promise<SatJson<InscriptionId>>;
|
|
84
|
+
getInscriptionsFromStartBlock(startHeight: number): Promise<InscriptionsJson<InscriptionId>>;
|
|
85
|
+
}
|
|
86
|
+
export declare class DefaultOrdinalsClient implements OrdinalsClient {
|
|
87
|
+
private basePath;
|
|
88
|
+
constructor(networkOrUrl?: string);
|
|
89
|
+
getInscriptionFromId(id: InscriptionId): Promise<InscriptionJson<InscriptionId, SatPoint>>;
|
|
90
|
+
getInscriptions(): Promise<InscriptionsJson<InscriptionId>>;
|
|
91
|
+
getInscriptionsFromBlock(height: number): Promise<InscriptionsJson<InscriptionId>>;
|
|
92
|
+
getInscriptionsFromOutPoint(outPoint: OutPoint): Promise<OutputJson>;
|
|
93
|
+
getInscriptionsFromSat(sat: number): Promise<SatJson<InscriptionId>>;
|
|
94
|
+
getInscriptionsFromStartBlock(startHeight: number): Promise<InscriptionsJson<InscriptionId>>;
|
|
95
|
+
getJson<T>(url: string): Promise<T>;
|
|
96
|
+
parseInscriptionsJson(inscriptionsJson: InscriptionsJson<string>): InscriptionsJson<InscriptionId>;
|
|
97
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultOrdinalsClient = exports.SatPoint = exports.OutPoint = exports.InscriptionId = exports.TESTNET_ORD_BASE_PATH = exports.MAINNET_ORD_BASE_PATH = exports.REGTEST_ORD_BASE_PATH = void 0;
|
|
4
|
+
exports.REGTEST_ORD_BASE_PATH = "http://0.0.0.0:3003";
|
|
5
|
+
exports.MAINNET_ORD_BASE_PATH = "https://ordinals-mainnet.gobob.xyz";
|
|
6
|
+
exports.TESTNET_ORD_BASE_PATH = "https://ordinals-testnet.gobob.xyz";
|
|
7
|
+
var InscriptionId;
|
|
8
|
+
(function (InscriptionId) {
|
|
9
|
+
function toString(id) {
|
|
10
|
+
return `${id.txid}i${id.index}`;
|
|
11
|
+
}
|
|
12
|
+
InscriptionId.toString = toString;
|
|
13
|
+
function fromString(id) {
|
|
14
|
+
const [txid, index] = id.split("i");
|
|
15
|
+
return {
|
|
16
|
+
txid,
|
|
17
|
+
index: parseInt(index, 10),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
InscriptionId.fromString = fromString;
|
|
21
|
+
})(InscriptionId || (exports.InscriptionId = InscriptionId = {}));
|
|
22
|
+
var OutPoint;
|
|
23
|
+
(function (OutPoint) {
|
|
24
|
+
function toString(id) {
|
|
25
|
+
return `${id.txid}:${id.vout}`;
|
|
26
|
+
}
|
|
27
|
+
OutPoint.toString = toString;
|
|
28
|
+
function fromString(id) {
|
|
29
|
+
const [txid, vout] = id.split(":");
|
|
30
|
+
return {
|
|
31
|
+
txid,
|
|
32
|
+
vout: parseInt(vout, 10),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
OutPoint.fromString = fromString;
|
|
36
|
+
})(OutPoint || (exports.OutPoint = OutPoint = {}));
|
|
37
|
+
var SatPoint;
|
|
38
|
+
(function (SatPoint) {
|
|
39
|
+
function toString(id) {
|
|
40
|
+
return `${OutPoint.toString(id.outpoint)}:${id.offset}`;
|
|
41
|
+
}
|
|
42
|
+
SatPoint.toString = toString;
|
|
43
|
+
function fromString(id) {
|
|
44
|
+
const [txid, vout, offset] = id.split(":");
|
|
45
|
+
return {
|
|
46
|
+
outpoint: {
|
|
47
|
+
txid,
|
|
48
|
+
vout: parseInt(vout, 10),
|
|
49
|
+
},
|
|
50
|
+
offset: parseInt(offset, 10),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
SatPoint.fromString = fromString;
|
|
54
|
+
})(SatPoint || (exports.SatPoint = SatPoint = {}));
|
|
55
|
+
class DefaultOrdinalsClient {
|
|
56
|
+
constructor(networkOrUrl = "mainnet") {
|
|
57
|
+
switch (networkOrUrl) {
|
|
58
|
+
case "mainnet":
|
|
59
|
+
this.basePath = exports.MAINNET_ORD_BASE_PATH;
|
|
60
|
+
break;
|
|
61
|
+
case "testnet":
|
|
62
|
+
this.basePath = exports.TESTNET_ORD_BASE_PATH;
|
|
63
|
+
break;
|
|
64
|
+
case "regtest":
|
|
65
|
+
this.basePath = exports.REGTEST_ORD_BASE_PATH;
|
|
66
|
+
break;
|
|
67
|
+
default:
|
|
68
|
+
this.basePath = networkOrUrl;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async getInscriptionFromId(id) {
|
|
72
|
+
const inscriptionJson = await this.getJson(`${this.basePath}/inscription/${InscriptionId.toString(id)}`);
|
|
73
|
+
return Object.assign(Object.assign({}, inscriptionJson), { children: inscriptionJson.children.map(InscriptionId.fromString), inscription_id: InscriptionId.fromString(inscriptionJson.inscription_id), next: (inscriptionJson.next != null) ? InscriptionId.fromString(inscriptionJson.next) : null, parent: (inscriptionJson.parent != null) ? InscriptionId.fromString(inscriptionJson.parent) : null, previous: (inscriptionJson.previous != null) ? InscriptionId.fromString(inscriptionJson.previous) : null, satpoint: SatPoint.fromString(inscriptionJson.satpoint) });
|
|
74
|
+
}
|
|
75
|
+
async getInscriptions() {
|
|
76
|
+
const inscriptionsJson = await this.getJson(`${this.basePath}/inscriptions`);
|
|
77
|
+
return this.parseInscriptionsJson(inscriptionsJson);
|
|
78
|
+
}
|
|
79
|
+
async getInscriptionsFromBlock(height) {
|
|
80
|
+
const inscriptionsJson = await this.getJson(`${this.basePath}/inscriptions/block/${height}`);
|
|
81
|
+
return this.parseInscriptionsJson(inscriptionsJson);
|
|
82
|
+
}
|
|
83
|
+
async getInscriptionsFromOutPoint(outPoint) {
|
|
84
|
+
return await this.getJson(`${this.basePath}/output/${OutPoint.toString(outPoint)}`);
|
|
85
|
+
}
|
|
86
|
+
async getInscriptionsFromSat(sat) {
|
|
87
|
+
const satJson = await this.getJson(`${this.basePath}/sat/${sat}`);
|
|
88
|
+
return Object.assign(Object.assign({}, satJson), { inscriptions: satJson.inscriptions.map(id => InscriptionId.fromString(id)) });
|
|
89
|
+
}
|
|
90
|
+
async getInscriptionsFromStartBlock(startHeight) {
|
|
91
|
+
const inscriptionsJson = await this.getJson(`${this.basePath}/inscriptions/${startHeight}`);
|
|
92
|
+
return this.parseInscriptionsJson(inscriptionsJson);
|
|
93
|
+
}
|
|
94
|
+
async getJson(url) {
|
|
95
|
+
const response = await fetch(url, {
|
|
96
|
+
headers: {
|
|
97
|
+
'Accept': 'application/json',
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
if (!response.ok) {
|
|
101
|
+
throw new Error(response.statusText);
|
|
102
|
+
}
|
|
103
|
+
return await response.json();
|
|
104
|
+
}
|
|
105
|
+
parseInscriptionsJson(inscriptionsJson) {
|
|
106
|
+
const ids = inscriptionsJson.inscriptions.map(id => InscriptionId.fromString(id));
|
|
107
|
+
return Object.assign(Object.assign({}, inscriptionsJson), { inscriptions: ids });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.DefaultOrdinalsClient = DefaultOrdinalsClient;
|
|
111
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ordinal-api/index.ts"],"names":[],"mappings":";;;AAIa,QAAA,qBAAqB,GAAG,qBAAqB,CAAC;AAM9C,QAAA,qBAAqB,GAAG,oCAAoC,CAAC;AAM7D,QAAA,qBAAqB,GAAG,oCAAoC,CAAC;AAQ1E,IAAc,aAAa,CAa1B;AAbD,WAAc,aAAa;IACvB,SAAgB,QAAQ,CAAC,EAAiB;QACtC,OAAO,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,KAAK,E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AAM,IAAI,CAAC,OAAO,CAA2B,GAAG,IAAI,CAAC,QAAQ,iBAAiB,WAAW,EAAE,CAAC,CAAC;QACtH,OAAO,IAAI,CAAC,qBAAqB,CAAC,gBAAgB,CAAC,CAAC;IACxD,CAAC;IAKD,KAAK,CAAC,OAAO,CAAI,GAAW;QACxB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;YAC9B,OAAO,EAAE;gBACL,QAAQ,EAAE,kBAAkB;aAC/B;SACJ,CAAC,CAAC;QACH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAgB,CAAC;IAC/C,CAAC;IAKD,qBAAqB,CAAC,gBAA0C;QAC5D,MAAM,GAAG,GAAG,gBAAgB,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;QAClF,uCACO,gBAAgB,KACnB,YAAY,EAAE,GAAG,IACnB;IACN,CAAC;CACJ;AAvGD,sDAuGC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as bitcoin from "bitcoinjs-lib";
|
|
3
|
+
export declare const MAX_CHUNK_SIZE = 520;
|
|
4
|
+
export interface Inscription {
|
|
5
|
+
contentType: Buffer;
|
|
6
|
+
content: Buffer;
|
|
7
|
+
}
|
|
8
|
+
export declare function createTextInscription(text: string): Inscription;
|
|
9
|
+
export declare function createInscription(contentType: string, content: Buffer): Inscription;
|
|
10
|
+
export declare function chunkContent(data: Buffer): Buffer[];
|
|
11
|
+
export declare function createInscriptionScript(xOnlyPublicKey: Buffer, inscription: Inscription): (number | Buffer)[];
|
|
12
|
+
export interface CommitTxData {
|
|
13
|
+
scriptTaproot: bitcoin.payments.Payment;
|
|
14
|
+
tapLeafScript: {
|
|
15
|
+
leafVersion: number;
|
|
16
|
+
script: Buffer;
|
|
17
|
+
controlBlock: Buffer;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export declare function createCommitTxData(network: bitcoin.Network, publicKey: Buffer, inscription: Inscription): CommitTxData;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.createCommitTxData = exports.createInscriptionScript = exports.chunkContent = exports.createInscription = exports.createTextInscription = exports.MAX_CHUNK_SIZE = void 0;
|
|
27
|
+
const bitcoin = __importStar(require("bitcoinjs-lib"));
|
|
28
|
+
const encoder = new TextEncoder();
|
|
29
|
+
exports.MAX_CHUNK_SIZE = 520;
|
|
30
|
+
function createTextInscription(text) {
|
|
31
|
+
return createInscription("text/plain;charset=utf-8", Buffer.from(encoder.encode(text)));
|
|
32
|
+
}
|
|
33
|
+
exports.createTextInscription = createTextInscription;
|
|
34
|
+
function createInscription(contentType, content) {
|
|
35
|
+
return {
|
|
36
|
+
contentType: Buffer.from(encoder.encode(contentType)),
|
|
37
|
+
content
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
exports.createInscription = createInscription;
|
|
41
|
+
function chunkContent(data) {
|
|
42
|
+
const body = [];
|
|
43
|
+
let start = 0;
|
|
44
|
+
while (start < data.length) {
|
|
45
|
+
body.push(data.subarray(start, start + exports.MAX_CHUNK_SIZE));
|
|
46
|
+
start += exports.MAX_CHUNK_SIZE;
|
|
47
|
+
}
|
|
48
|
+
return body;
|
|
49
|
+
}
|
|
50
|
+
exports.chunkContent = chunkContent;
|
|
51
|
+
function createInscriptionScript(xOnlyPublicKey, inscription) {
|
|
52
|
+
const protocolId = Buffer.from(encoder.encode("ord"));
|
|
53
|
+
return [
|
|
54
|
+
xOnlyPublicKey,
|
|
55
|
+
bitcoin.opcodes.OP_CHECKSIG,
|
|
56
|
+
bitcoin.opcodes.OP_0,
|
|
57
|
+
bitcoin.opcodes.OP_IF,
|
|
58
|
+
protocolId,
|
|
59
|
+
1,
|
|
60
|
+
1,
|
|
61
|
+
inscription.contentType,
|
|
62
|
+
bitcoin.opcodes.OP_0,
|
|
63
|
+
...chunkContent(inscription.content),
|
|
64
|
+
bitcoin.opcodes.OP_ENDIF,
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
exports.createInscriptionScript = createInscriptionScript;
|
|
68
|
+
function toXOnly(pubkey) {
|
|
69
|
+
return pubkey.subarray(1, 33);
|
|
70
|
+
}
|
|
71
|
+
function createCommitTxData(network, publicKey, inscription) {
|
|
72
|
+
var _a;
|
|
73
|
+
const xOnlyPublicKey = toXOnly(publicKey);
|
|
74
|
+
const script = createInscriptionScript(xOnlyPublicKey, inscription);
|
|
75
|
+
const outputScript = bitcoin.script.compile(script);
|
|
76
|
+
const scriptTree = {
|
|
77
|
+
output: outputScript,
|
|
78
|
+
redeemVersion: 192,
|
|
79
|
+
};
|
|
80
|
+
const scriptTaproot = bitcoin.payments.p2tr({
|
|
81
|
+
internalPubkey: xOnlyPublicKey,
|
|
82
|
+
scriptTree,
|
|
83
|
+
redeem: scriptTree,
|
|
84
|
+
network,
|
|
85
|
+
});
|
|
86
|
+
const cblock = (_a = scriptTaproot.witness) === null || _a === void 0 ? void 0 : _a[scriptTaproot.witness.length - 1];
|
|
87
|
+
const tapLeafScript = {
|
|
88
|
+
leafVersion: scriptTaproot.redeemVersion,
|
|
89
|
+
script: outputScript,
|
|
90
|
+
controlBlock: cblock,
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
scriptTaproot,
|
|
94
|
+
tapLeafScript,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
exports.createCommitTxData = createCommitTxData;
|
|
98
|
+
//# sourceMappingURL=commit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit.js","sourceRoot":"","sources":["../../src/ordinals/commit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAAyC;AAEzC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAGrB,QAAA,cAAc,GAAG,GAAG,CAAC;AAUlC,SAAgB,qBAAqB,CAAC,IAAY;IAC9C,OAAO,iBAAiB,CACpB,0BAA0B,EAC1B,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CACpC,CAAC;AACN,CAAC;AALD,sDAKC;AAKD,SAAgB,iBAAiB,CAAC,WAAmB,EAAE,OAAe;IAClE,OAAO;QAEH,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,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AG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAEpD,MAAM,UAAU,GAAG;QACf,MAAM,EAAE,YAAY;QACpB,aAAa,EAAE,GAAG;KACrB,CAAC;IAEF,MAAM,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;QACxC,cAAc,EAAE,cAAc;QAC9B,UAAU;QACV,MAAM,EAAE,UAAU;QAClB,OAAO;KACV,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,MAAA,aAAa,CAAC,OAAO,0CAAG,aAAa,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAEzE,MAAM,aAAa,GAAG;QAClB,WAAW,EAAE,aAAa,CAAC,aAAc;QACzC,MAAM,EAAE,YAAY;QACpB,YAAY,EAAE,MAAM;KACvB,CAAC;IAEF,OAAO;QACH,aAAa;QACb,aAAa;KAChB,CAAC;AACN,CAAC;AAlCD,gDAkCC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as bitcoin from "bitcoinjs-lib";
|
|
2
|
+
import { RemoteSigner } from "./signer";
|
|
3
|
+
import { Inscription, createInscription, createTextInscription } from "./commit";
|
|
4
|
+
export { RemoteSigner, createInscription, createTextInscription, Inscription };
|
|
5
|
+
export declare function inscribeData(signer: RemoteSigner, toAddress: string, feeRate: number, inscription: Inscription, postage?: number): Promise<bitcoin.Transaction>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.inscribeData = exports.createTextInscription = exports.createInscription = void 0;
|
|
27
|
+
const bitcoin = __importStar(require("bitcoinjs-lib"));
|
|
28
|
+
const signer_1 = require("./signer");
|
|
29
|
+
const commit_1 = require("./commit");
|
|
30
|
+
Object.defineProperty(exports, "createInscription", { enumerable: true, get: function () { return commit_1.createInscription; } });
|
|
31
|
+
Object.defineProperty(exports, "createTextInscription", { enumerable: true, get: function () { return commit_1.createTextInscription; } });
|
|
32
|
+
const reveal_1 = require("./reveal");
|
|
33
|
+
function estimateTxSize(network, publicKey, commitTxData, toAddress, amount) {
|
|
34
|
+
const psbt = new bitcoin.Psbt({ network });
|
|
35
|
+
const { scriptTaproot, tapLeafScript } = commitTxData;
|
|
36
|
+
psbt.addInput({
|
|
37
|
+
hash: Buffer.alloc(32, 0),
|
|
38
|
+
index: 0,
|
|
39
|
+
witnessUtxo: {
|
|
40
|
+
value: amount,
|
|
41
|
+
script: scriptTaproot.output,
|
|
42
|
+
},
|
|
43
|
+
tapLeafScript: [tapLeafScript],
|
|
44
|
+
});
|
|
45
|
+
psbt.addOutput({
|
|
46
|
+
value: amount,
|
|
47
|
+
address: toAddress,
|
|
48
|
+
});
|
|
49
|
+
psbt.signInput(0, new signer_1.DummySigner(publicKey));
|
|
50
|
+
psbt.finalizeInput(0, (0, reveal_1.customFinalizer)(commitTxData));
|
|
51
|
+
const tx = psbt.extractTransaction();
|
|
52
|
+
return tx.virtualSize();
|
|
53
|
+
}
|
|
54
|
+
async function inscribeData(signer, toAddress, feeRate, inscription, postage = 10000) {
|
|
55
|
+
const bitcoinNetwork = await signer.getNetwork();
|
|
56
|
+
const publicKey = Buffer.from(await signer.getPublicKey(), "hex");
|
|
57
|
+
const commitTxData = (0, commit_1.createCommitTxData)(bitcoinNetwork, publicKey, inscription);
|
|
58
|
+
const revealTxSize = estimateTxSize(bitcoinNetwork, publicKey, commitTxData, toAddress, postage);
|
|
59
|
+
const revealFee = revealTxSize * feeRate;
|
|
60
|
+
const commitTxAmount = revealFee + postage;
|
|
61
|
+
const commitAddress = commitTxData.scriptTaproot.address;
|
|
62
|
+
const commitTxId = await signer.sendToAddress(commitAddress, commitTxAmount);
|
|
63
|
+
const commitTx = await signer.getTransaction(commitTxId);
|
|
64
|
+
const scriptPubKey = bitcoin.address.toOutputScript(commitAddress, bitcoinNetwork);
|
|
65
|
+
const commitUtxoIndex = commitTx.outs.findIndex(out => out.script.equals(scriptPubKey));
|
|
66
|
+
const commitTxResult = {
|
|
67
|
+
tx: commitTx,
|
|
68
|
+
outputIndex: commitUtxoIndex,
|
|
69
|
+
outputAmount: commitTxAmount,
|
|
70
|
+
};
|
|
71
|
+
const revealPsbt = (0, reveal_1.createRevealTx)(bitcoinNetwork, commitTxData, commitTxResult, toAddress, postage);
|
|
72
|
+
const revealTx = await (0, reveal_1.signRevealTx)(signer, commitTxData, revealPsbt);
|
|
73
|
+
return revealTx;
|
|
74
|
+
}
|
|
75
|
+
exports.inscribeData = inscribeData;
|
|
76
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sour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|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as bitcoin from "bitcoinjs-lib";
|
|
3
|
+
import { RemoteSigner } from "./signer";
|
|
4
|
+
import { CommitTxData } from "./commit";
|
|
5
|
+
export interface CommitTxResult {
|
|
6
|
+
tx: bitcoin.Transaction;
|
|
7
|
+
outputIndex: number;
|
|
8
|
+
outputAmount: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function createRevealTx(network: bitcoin.Network, commitTxData: CommitTxData, commitTxResult: CommitTxResult, toAddress: string, amount: number): bitcoin.Psbt;
|
|
11
|
+
export declare const customFinalizer: (commitTxData: CommitTxData) => (inputIndex: number, input: any) => {
|
|
12
|
+
finalScriptWitness: Buffer;
|
|
13
|
+
};
|
|
14
|
+
export declare function signRevealTx(signer: RemoteSigner, commitTxData: CommitTxData, psbt: bitcoin.Psbt): Promise<bitcoin.Transaction>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.signRevealTx = exports.customFinalizer = exports.createRevealTx = void 0;
|
|
27
|
+
const bitcoin = __importStar(require("bitcoinjs-lib"));
|
|
28
|
+
const psbtUtils = __importStar(require("bitcoinjs-lib/src/psbt/psbtutils"));
|
|
29
|
+
const { witnessStackToScriptWitness } = psbtUtils;
|
|
30
|
+
function createRevealTx(network, commitTxData, commitTxResult, toAddress, amount) {
|
|
31
|
+
const { scriptTaproot, tapLeafScript } = commitTxData;
|
|
32
|
+
const psbt = new bitcoin.Psbt({ network });
|
|
33
|
+
psbt.addInput({
|
|
34
|
+
hash: commitTxResult.tx.getId(),
|
|
35
|
+
index: commitTxResult.outputIndex,
|
|
36
|
+
witnessUtxo: {
|
|
37
|
+
value: commitTxResult.outputAmount,
|
|
38
|
+
script: scriptTaproot.output,
|
|
39
|
+
},
|
|
40
|
+
nonWitnessUtxo: commitTxResult.tx.toBuffer(),
|
|
41
|
+
tapLeafScript: [tapLeafScript],
|
|
42
|
+
});
|
|
43
|
+
psbt.addOutput({
|
|
44
|
+
value: amount,
|
|
45
|
+
address: toAddress,
|
|
46
|
+
});
|
|
47
|
+
return psbt;
|
|
48
|
+
}
|
|
49
|
+
exports.createRevealTx = createRevealTx;
|
|
50
|
+
const customFinalizer = (commitTxData) => {
|
|
51
|
+
const { tapLeafScript } = commitTxData;
|
|
52
|
+
return (inputIndex, input) => {
|
|
53
|
+
const witness = [input.tapScriptSig[inputIndex].signature]
|
|
54
|
+
.concat(tapLeafScript.script)
|
|
55
|
+
.concat(tapLeafScript.controlBlock);
|
|
56
|
+
return {
|
|
57
|
+
finalScriptWitness: witnessStackToScriptWitness(witness),
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
exports.customFinalizer = customFinalizer;
|
|
62
|
+
async function signRevealTx(signer, commitTxData, psbt) {
|
|
63
|
+
psbt = await signer.signInput(0, psbt);
|
|
64
|
+
psbt.finalizeInput(0, (0, exports.customFinalizer)(commitTxData));
|
|
65
|
+
return psbt.extractTransaction();
|
|
66
|
+
}
|
|
67
|
+
exports.signRevealTx = signRevealTx;
|
|
68
|
+
//# sourceMappingURL=reveal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reveal.js","sourceRoot":"","sources":["../../src/ordinals/reveal.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAAyC;AACzC,4EAA8D;AAK9D,MAAM,EAAE,2BAA2B,EAAE,GAAG,SAAS,CAAC;AAWlD,SAAgB,cAAc,CAC1B,OAAwB,EACxB,YAA0B,EAC1B,cAA8B,EAC9B,SAAiB,EACjB,MAAc;IAEd,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,GAAG,YAAY,CAAC;IAEtD,MAAM,IAAI,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;IAE3C,IAAI,CAAC,QAAQ,CAAC;QACV,IAAI,EAAE,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE;QAC/B,KAAK,EAAE,cAAc,CAAC,WAAW;QACjC,WAAW,EAAE;YACT,KAAK,EAAE,cAAc,CAAC,YAAY;YAClC,MAAM,EAAE,aAAa,CAAC,MAAO;SAChC;QACD,cAAc,EAAE,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE;QAC5C,aAAa,EAAE,CAAC,aAAa,CAAC;KACjC,CAAC,CAAC;IAEH,IAAI,CAAC,SAAS,CAAC;QACX,KAAK,EAAE,MAAM;QACb,OAAO,EAAE,SAAS;KACrB,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AAChB,CAAC;AA5BD,wCA4BC;AAEM,MAAM,eAAe,GAAG,CAAC,YAA0B,EAAE,EAAE;IAC1D,MAAM,EAAE,aAAa,EAAE,GAAG,YAAY,CAAC;IAEvC,OAAO,CAAC,UAAkB,EAAE,KAAU,EAAE,EAAE;QACtC,MAAM,OAAO,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC;aACrD,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC;aAC5B,MAAM,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;QAExC,OAAO;YACH,kBAAkB,EAAE,2BAA2B,CAAC,OAAO,CAAC;SAC3D,CAAC;IACN,CAAC,CAAC;AACN,CAAC,CAAA;AAZY,QAAA,eAAe,mBAY3B;AAEM,KAAK,UAAU,YAAY,CAC9B,MAAoB,EACpB,YAA0B,EAC1B,IAAkB;IAGlB,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;AAZD,oCAYC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Network, Psbt, Signer, Transaction } from "bitcoinjs-lib";
|
|
3
|
+
export declare class DummySigner implements Signer {
|
|
4
|
+
publicKey: Buffer;
|
|
5
|
+
constructor(publicKey: Buffer);
|
|
6
|
+
sign(_hash: Buffer, _lowR?: boolean | undefined): Buffer;
|
|
7
|
+
signSchnorr(hash: Buffer): Buffer;
|
|
8
|
+
}
|
|
9
|
+
export interface RemoteSigner {
|
|
10
|
+
getNetwork(): Promise<Network>;
|
|
11
|
+
getPublicKey(): Promise<string>;
|
|
12
|
+
sendToAddress(toAddress: string, amount: number): Promise<string>;
|
|
13
|
+
getTransaction(txId: string): Promise<Transaction>;
|
|
14
|
+
signInput(inputIndex: number, psbt: Psbt): Promise<Psbt>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DummySigner = void 0;
|
|
4
|
+
class DummySigner {
|
|
5
|
+
constructor(publicKey) {
|
|
6
|
+
this.publicKey = publicKey;
|
|
7
|
+
}
|
|
8
|
+
sign(_hash, _lowR) {
|
|
9
|
+
return Buffer.alloc(64, 0);
|
|
10
|
+
}
|
|
11
|
+
signSchnorr(hash) {
|
|
12
|
+
return Buffer.alloc(64, 0);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.DummySigner = DummySigner;
|
|
16
|
+
;
|
|
17
|
+
//# sourceMappingURL=signer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../../src/ordinals/signer.ts"],"names":[],"mappings":";;;AAKA,MAAa,WAAW;IAEpB,YAAY,SAAiB;QACzB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,CAAC;IACD,IAAI,CAAC,KAAa,EAAE,KAA2B;QAE3C,OAAO,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC/B,CAAC;IACD,WAAW,CAAC,IAAY;QAEpB,OAAO,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC/B,CAAC;CACJ;AAbD,kCAaC;AAsCA,CAAC"}
|
package/dist/relay.d.ts
CHANGED
|
@@ -4,11 +4,13 @@ export interface BitcoinTxInfo {
|
|
|
4
4
|
inputVector: string;
|
|
5
5
|
outputVector: string;
|
|
6
6
|
locktime: string;
|
|
7
|
+
witnessVector?: string;
|
|
7
8
|
}
|
|
8
|
-
export declare function getBitcoinTxInfo(electrsClient: ElectrsClient, txId: string): Promise<BitcoinTxInfo>;
|
|
9
|
+
export declare function getBitcoinTxInfo(electrsClient: ElectrsClient, txId: string, forWitness?: boolean): Promise<BitcoinTxInfo>;
|
|
9
10
|
export interface BitcoinTxProof {
|
|
10
11
|
merkleProof: string;
|
|
11
12
|
txIndexInBlock: number;
|
|
12
13
|
bitcoinHeaders: string;
|
|
13
14
|
}
|
|
14
15
|
export declare function getBitcoinTxProof(electrsClient: ElectrsClient, txId: string, txProofDifficultyFactor: number): Promise<BitcoinTxProof>;
|
|
16
|
+
export declare function getBitcoinHeaders(electrsClient: ElectrsClient, startHeight: number, numBlocks: number): Promise<string>;
|
package/dist/relay.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBitcoinTxProof = exports.getBitcoinTxInfo = void 0;
|
|
3
|
+
exports.getBitcoinHeaders = exports.getBitcoinTxProof = exports.getBitcoinTxInfo = void 0;
|
|
4
4
|
const bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
|
-
async function getBitcoinTxInfo(electrsClient, txId) {
|
|
6
|
+
async function getBitcoinTxInfo(electrsClient, txId, forWitness) {
|
|
7
7
|
const txHex = await electrsClient.getTransactionHex(txId);
|
|
8
8
|
const tx = bitcoinjs_lib_1.Transaction.fromHex(txHex);
|
|
9
9
|
const versionBuffer = Buffer.allocUnsafe(4);
|
|
@@ -14,23 +14,30 @@ async function getBitcoinTxInfo(electrsClient, txId) {
|
|
|
14
14
|
version: versionBuffer.toString("hex"),
|
|
15
15
|
inputVector: (0, utils_1.encodeRawInput)(tx).toString("hex"),
|
|
16
16
|
outputVector: (0, utils_1.encodeRawOutput)(tx).toString("hex"),
|
|
17
|
-
locktime: locktimeBuffer.toString("hex")
|
|
17
|
+
locktime: locktimeBuffer.toString("hex"),
|
|
18
|
+
witnessVector: forWitness ? (0, utils_1.encodeRawWitness)(tx).toString("hex") : undefined,
|
|
19
|
+
witnessVector: forWitness ? (0, utils_1.encodeRawWitness)(tx).toString("hex") : undefined,
|
|
18
20
|
};
|
|
19
21
|
}
|
|
20
22
|
exports.getBitcoinTxInfo = getBitcoinTxInfo;
|
|
21
23
|
async function getBitcoinTxProof(electrsClient, txId, txProofDifficultyFactor) {
|
|
22
24
|
const merkleProof = await electrsClient.getMerkleProof(txId);
|
|
23
|
-
const
|
|
24
|
-
const blockHeights = range(merkleProof.blockHeight, merkleProof.blockHeight + txProofDifficultyFactor);
|
|
25
|
-
const bitcoinHeaders = await Promise.all(blockHeights.map(async (height) => {
|
|
26
|
-
const hash = await electrsClient.getBlockHash(height);
|
|
27
|
-
return electrsClient.getBlockHeader(hash);
|
|
28
|
-
}));
|
|
25
|
+
const bitcoinHeaders = await getBitcoinHeaders(electrsClient, merkleProof.blockHeight, txProofDifficultyFactor);
|
|
29
26
|
return {
|
|
30
27
|
merkleProof: merkleProof.merkle,
|
|
31
28
|
txIndexInBlock: merkleProof.pos,
|
|
32
|
-
bitcoinHeaders: bitcoinHeaders
|
|
29
|
+
bitcoinHeaders: bitcoinHeaders,
|
|
33
30
|
};
|
|
34
31
|
}
|
|
35
32
|
exports.getBitcoinTxProof = getBitcoinTxProof;
|
|
33
|
+
async function getBitcoinHeaders(electrsClient, startHeight, numBlocks) {
|
|
34
|
+
const range = (start, end) => Array.from({ length: end - start }, (_element, index) => index + start);
|
|
35
|
+
const blockHeights = range(startHeight, startHeight + numBlocks);
|
|
36
|
+
const bitcoinHeaders = await Promise.all(blockHeights.map(async (height) => {
|
|
37
|
+
const hash = await electrsClient.getBlockHash(height);
|
|
38
|
+
return electrsClient.getBlockHeader(hash);
|
|
39
|
+
}));
|
|
40
|
+
return bitcoinHeaders.join('');
|
|
41
|
+
}
|
|
42
|
+
exports.getBitcoinHeaders = getBitcoinHeaders;
|
|
36
43
|
//# sourceMappingURL=relay.js.map
|
package/dist/relay.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relay.js","sourceRoot":"","sources":["../src/relay.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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,CAAA;AACL,CAAC;AAbD,8CAaC;AA0BM,KAAK,UAAU,iBAAiB,CACnC,aAA4B,EAC5B,WAAmB,EACnB,SAAiB;IAEjB,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,GAAW,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,GAAG,KAAK,EAAE,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC;IACtH,MAAM,YAAY,GAAG,KAAK,CAAC,WAAW,EAAE,WAAW,GAAG,SAAS,CAAC,CAAC;IAEjE,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAC,MAAM,EAAC,EAAE;QACrE,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QACtD,OAAO,aAAa,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC,CAAC;IAEJ,OAAO,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACnC,CAAC;AAdD,8CAcC"}
|
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":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C;QACxE,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;KAC3C,CAAC;AACN,CAAC;AAXD,wCAWC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gobob/bob-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "ts-mocha test/*.ts",
|
|
8
|
+
"deploy-relay": "ts-node scripts/init-bridge.ts",
|
|
8
9
|
"build": "tsc -p tsconfig.json"
|
|
9
10
|
},
|
|
10
11
|
"files": [
|
|
@@ -18,12 +19,15 @@
|
|
|
18
19
|
"devDependencies": {
|
|
19
20
|
"@types/chai": "^4.3.6",
|
|
20
21
|
"@types/mocha": "^10.0.2",
|
|
21
|
-
"@types/node": "^20.8.
|
|
22
|
+
"@types/node": "^20.8.9",
|
|
22
23
|
"chai": "^4.3.10",
|
|
24
|
+
"ecpair": "^2.1.0",
|
|
23
25
|
"mocha": "^10.2.0",
|
|
26
|
+
"tiny-secp256k1": "^2.2.3",
|
|
24
27
|
"ts-mocha": "^10.0.0",
|
|
25
28
|
"ts-node-dev": "^2.0.0",
|
|
26
|
-
"typescript": "^5.2.2"
|
|
29
|
+
"typescript": "^5.2.2",
|
|
30
|
+
"yargs": "^17.5.1"
|
|
27
31
|
},
|
|
28
32
|
"dependencies": {
|
|
29
33
|
"bitcoinjs-lib": "^6.1.5"
|