@gobob/bob-sdk 1.1.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -0
- package/dist/esplora.d.ts +98 -0
- package/dist/{electrs.js → esplora.js} +15 -6
- package/dist/esplora.js.map +1 -0
- package/dist/gateway.d.ts +30 -0
- package/dist/gateway.js +56 -0
- package/dist/gateway.js.map +1 -0
- package/dist/helpers.d.ts +2 -2
- package/dist/helpers.js +6 -7
- package/dist/helpers.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/inscription.d.ts +18 -12
- package/dist/inscription.js +92 -27
- package/dist/inscription.js.map +1 -1
- package/dist/ordinal-api/index.d.ts +25 -15
- package/dist/ordinal-api/index.js +19 -4
- package/dist/ordinal-api/index.js.map +1 -1
- package/dist/ordinals/commit.d.ts +1 -10
- package/dist/ordinals/commit.js +3 -45
- package/dist/ordinals/commit.js.map +1 -1
- package/dist/ordinals/index.d.ts +2 -2
- package/dist/ordinals/index.js +1 -4
- package/dist/ordinals/index.js.map +1 -1
- package/dist/ordinals/reveal.d.ts +0 -1
- package/dist/ordinals/reveal.js +3 -3
- package/dist/ordinals/reveal.js.map +1 -1
- package/dist/ordinals/signer.d.ts +0 -1
- package/dist/relay.d.ts +4 -4
- package/dist/relay.js +11 -12
- package/dist/relay.js.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +42 -5
- package/dist/utils.js.map +1 -1
- package/dist/wallet/address.d.ts +2 -0
- package/dist/wallet/address.js +19 -0
- package/dist/wallet/address.js.map +1 -0
- package/dist/wallet/index.d.ts +2 -0
- package/dist/wallet/index.js +19 -0
- package/dist/wallet/index.js.map +1 -0
- package/dist/wallet/inscriptions.d.ts +4 -0
- package/dist/wallet/inscriptions.js +43 -0
- package/dist/wallet/inscriptions.js.map +1 -0
- package/dist/wallet/utxo.d.ts +23 -0
- package/dist/wallet/utxo.js +91 -0
- package/dist/wallet/utxo.js.map +1 -0
- package/package.json +14 -12
- package/dist/electrs.d.ts +0 -38
- package/dist/electrs.js.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# BOB SDK
|
|
2
|
+
|
|
3
|
+
The BOB SDK helps you interact with BOB and Bitcoin, including Ordinals, BRC20, Runes, and more.
|
|
4
|
+
|
|
5
|
+
## Learn more
|
|
6
|
+
|
|
7
|
+
- [Website](https://www.gobob.xyz/)
|
|
8
|
+
- [Docs](https://docs.gobob.xyz/)
|
|
9
|
+
|
|
10
|
+
## Using the sdk in your project
|
|
11
|
+
Install `@gobob/bob-sdk` with your package manager of choice.
|
|
12
|
+
|
|
13
|
+
```shell
|
|
14
|
+
pnpm i @gobob/bob-sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
or
|
|
18
|
+
```shell
|
|
19
|
+
yarn add @gobob/bob-sdk
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
or
|
|
23
|
+
```shell
|
|
24
|
+
npm i @gobob/bob-sdk
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Building BOB sdk
|
|
28
|
+
|
|
29
|
+
### Clone the repository
|
|
30
|
+
Clone the repository and change to the `sdk` subfolder.
|
|
31
|
+
```shell
|
|
32
|
+
git clone git@github.com:bob-collective/bob.git
|
|
33
|
+
cd bob/sdk
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Install dependencies
|
|
37
|
+
We use `pnpm` in the examples below. But the steps below should also work when using `yarn` or `npm` instead.
|
|
38
|
+
|
|
39
|
+
```shell
|
|
40
|
+
pnpm i
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Build
|
|
44
|
+
```shell
|
|
45
|
+
pnpm build
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Test
|
|
49
|
+
|
|
50
|
+
```shell
|
|
51
|
+
pnpm test
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Contributing
|
|
55
|
+
|
|
56
|
+
BOB is an open-source project. We welcome contributions of all sorts. There are many ways to help, from reporting issues, contributing code, and helping us improve our community.
|
|
57
|
+
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
|
|
58
|
+
|
|
59
|
+
1. Set up git so you can [sign your commits](https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work) (Alternative link: [GitHub: Signing commits](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits))
|
|
60
|
+
Unsigned PRs cannot be merged, so do not skip this step.
|
|
61
|
+
2. Fork the Project
|
|
62
|
+
3. Create your Feature Branch (git checkout -b yourname/AmazingFeature)
|
|
63
|
+
4. Commit your Changes (git commit -m 'Add some AmazingFeature')
|
|
64
|
+
5. Push to the Branch (git push origin yourname/AmazingFeature)
|
|
65
|
+
6. Open a Pull Request with a description of feature you are adding
|
|
66
|
+
|
|
67
|
+
If you are searching for a place to start or would like to discuss features, reach out to us:
|
|
68
|
+
|
|
69
|
+
- [Discord](https://discord.com/invite/gobob)
|
|
70
|
+
|
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
export interface MerkleProof {
|
|
5
|
+
blockHeight: number;
|
|
6
|
+
merkle: string;
|
|
7
|
+
pos: number;
|
|
8
|
+
}
|
|
9
|
+
export interface UTXO {
|
|
10
|
+
txid: string;
|
|
11
|
+
vout: number;
|
|
12
|
+
value: number;
|
|
13
|
+
confirmed: boolean;
|
|
14
|
+
height?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface Transaction {
|
|
17
|
+
txid: string;
|
|
18
|
+
version: number;
|
|
19
|
+
locktime: number;
|
|
20
|
+
size: number;
|
|
21
|
+
weight: number;
|
|
22
|
+
fee: number;
|
|
23
|
+
vin: Array<{
|
|
24
|
+
txid: string;
|
|
25
|
+
vout: number;
|
|
26
|
+
is_coinbase: boolean;
|
|
27
|
+
scriptsig: string;
|
|
28
|
+
scriptsig_asm: string;
|
|
29
|
+
inner_redeemscript_asm?: string;
|
|
30
|
+
inner_witnessscript_asm?: string;
|
|
31
|
+
sequence?: number;
|
|
32
|
+
witness?: string[];
|
|
33
|
+
prevout: {
|
|
34
|
+
scriptpubkey: string;
|
|
35
|
+
scriptpubkey_asm: string;
|
|
36
|
+
scriptpubkey_type: string;
|
|
37
|
+
scriptpubkey_address: string;
|
|
38
|
+
value: number;
|
|
39
|
+
} | null;
|
|
40
|
+
}>;
|
|
41
|
+
vout: Array<{
|
|
42
|
+
scriptpubkey: string;
|
|
43
|
+
scriptpubkey_asm?: string;
|
|
44
|
+
scriptpubkey_type?: string;
|
|
45
|
+
scriptpubkey_address?: string;
|
|
46
|
+
value: number;
|
|
47
|
+
}>;
|
|
48
|
+
status: {
|
|
49
|
+
confirmed: boolean;
|
|
50
|
+
block_height: number;
|
|
51
|
+
block_hash: string;
|
|
52
|
+
block_time: number;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export interface Block {
|
|
56
|
+
id: string;
|
|
57
|
+
height: number;
|
|
58
|
+
version: number;
|
|
59
|
+
timestamp: number;
|
|
60
|
+
bits: number;
|
|
61
|
+
nonce: number;
|
|
62
|
+
difficulty: number;
|
|
63
|
+
merkle_root: string;
|
|
64
|
+
tx_count: number;
|
|
65
|
+
size: number;
|
|
66
|
+
weight: number;
|
|
67
|
+
previousblockhash: string | null;
|
|
68
|
+
mediantime: number;
|
|
69
|
+
}
|
|
70
|
+
export interface EsploraClient {
|
|
71
|
+
getLatestHeight(): Promise<number>;
|
|
72
|
+
getBlock(hash: string): Promise<Block>;
|
|
73
|
+
getBlockHash(height: number): Promise<string>;
|
|
74
|
+
getBlockHeader(hash: string): Promise<string>;
|
|
75
|
+
getTransaction(txId: string): Promise<Transaction>;
|
|
76
|
+
getTransactionHex(txId: string): Promise<string>;
|
|
77
|
+
getMerkleProof(txId: string): Promise<MerkleProof>;
|
|
78
|
+
getFeeEstimate(confirmationTarget: number): Promise<number>;
|
|
79
|
+
getAddressUtxos(address: string): Promise<Array<UTXO>>;
|
|
80
|
+
broadcastTx(txHex: string): Promise<string>;
|
|
81
|
+
}
|
|
82
|
+
export declare class DefaultEsploraClient implements EsploraClient {
|
|
83
|
+
private basePath;
|
|
84
|
+
constructor(networkOrUrl?: string);
|
|
85
|
+
getLatestHeight(): Promise<number>;
|
|
86
|
+
getBlock(blockHash: string): Promise<Block>;
|
|
87
|
+
getBlockHash(height: number): Promise<string>;
|
|
88
|
+
getBlockHeader(hash: string): Promise<string>;
|
|
89
|
+
getBlockHeaderAt(height: number): Promise<string>;
|
|
90
|
+
getTransaction(txId: string): Promise<Transaction>;
|
|
91
|
+
getTransactionHex(txId: string): Promise<string>;
|
|
92
|
+
getMerkleProof(txId: string): Promise<MerkleProof>;
|
|
93
|
+
getFeeEstimate(confirmationTarget: number): Promise<number>;
|
|
94
|
+
getAddressUtxos(address: string, confirmed?: boolean): Promise<Array<UTXO>>;
|
|
95
|
+
broadcastTx(txHex: string): Promise<string>;
|
|
96
|
+
getJson<T>(url: string): Promise<T>;
|
|
97
|
+
getText(url: string): Promise<string>;
|
|
98
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.DefaultEsploraClient = exports.REGTEST_ESPLORA_BASE_PATH = exports.TESTNET_ESPLORA_BASE_PATH = exports.MAINNET_ESPLORA_BASE_PATH = void 0;
|
|
4
4
|
exports.MAINNET_ESPLORA_BASE_PATH = "https://btc-mainnet.gobob.xyz";
|
|
5
5
|
exports.TESTNET_ESPLORA_BASE_PATH = "https://btc-testnet.gobob.xyz";
|
|
6
6
|
exports.REGTEST_ESPLORA_BASE_PATH = "http://localhost:3003";
|
|
7
|
-
function
|
|
7
|
+
function encodeEsploraMerkleProof(merkle) {
|
|
8
8
|
return merkle.map(item => Buffer.from(item, "hex").reverse().toString("hex")).join('');
|
|
9
9
|
}
|
|
10
|
-
class
|
|
10
|
+
class DefaultEsploraClient {
|
|
11
11
|
constructor(networkOrUrl = "mainnet") {
|
|
12
12
|
switch (networkOrUrl) {
|
|
13
13
|
case "mainnet":
|
|
@@ -23,6 +23,12 @@ class DefaultElectrsClient {
|
|
|
23
23
|
this.basePath = networkOrUrl;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
+
async getLatestHeight() {
|
|
27
|
+
return parseInt(await this.getText(`${this.basePath}/blocks/tip/height`), 10);
|
|
28
|
+
}
|
|
29
|
+
async getBlock(blockHash) {
|
|
30
|
+
return this.getJson(`${this.basePath}/block/${blockHash}`);
|
|
31
|
+
}
|
|
26
32
|
async getBlockHash(height) {
|
|
27
33
|
return this.getText(`${this.basePath}/block-height/${height}`);
|
|
28
34
|
}
|
|
@@ -33,6 +39,9 @@ class DefaultElectrsClient {
|
|
|
33
39
|
const blockHash = await this.getBlockHash(height);
|
|
34
40
|
return await this.getBlockHeader(blockHash);
|
|
35
41
|
}
|
|
42
|
+
async getTransaction(txId) {
|
|
43
|
+
return this.getJson(`${this.basePath}/tx/${txId}`);
|
|
44
|
+
}
|
|
36
45
|
async getTransactionHex(txId) {
|
|
37
46
|
return this.getText(`${this.basePath}/tx/${txId}/hex`);
|
|
38
47
|
}
|
|
@@ -40,7 +49,7 @@ class DefaultElectrsClient {
|
|
|
40
49
|
const response = await this.getJson(`${this.basePath}/tx/${txId}/merkle-proof`);
|
|
41
50
|
return {
|
|
42
51
|
blockHeight: response.block_height,
|
|
43
|
-
merkle:
|
|
52
|
+
merkle: encodeEsploraMerkleProof(response.merkle),
|
|
44
53
|
pos: response.pos,
|
|
45
54
|
};
|
|
46
55
|
}
|
|
@@ -84,5 +93,5 @@ class DefaultElectrsClient {
|
|
|
84
93
|
return await response.text();
|
|
85
94
|
}
|
|
86
95
|
}
|
|
87
|
-
exports.
|
|
88
|
-
//# sourceMappingURL=
|
|
96
|
+
exports.DefaultEsploraClient = DefaultEsploraClient;
|
|
97
|
+
//# sourceMappingURL=esplora.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esplora.js","sourceRoot":"","sources":["../src/esplora.ts"],"names":[],"mappings":";;;AAIa,QAAA,yBAAyB,GAAG,+BAA+B,CAAC;AAK5D,QAAA,yBAAyB,GAAG,+BAA+B,CAAC;AAK5D,QAAA,yBAAyB,GAAG,uBAAuB,CAAC;AAoQjE,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,KAAK,SAAS;gBACV,IAAI,CAAC,QAAQ,GAAG,iCAAyB,CAAC;gBAC1C,MAAM;YACV,KAAK,SAAS;gBACV,IAAI,CAAC,QAAQ,GAAG,iCAAyB,CAAC;gBAC1C,MAAM;YACV;gBACI,IAAI,CAAC,QAAQ,GAAG,YAAY,CAAC;QACrC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,eAAe;QACjB,OAAO,QAAQ,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,oBAAoB,CAAC,EAAE,EAAE,CAAC,CAAC;IAClF,CAAC;IAKD,KAAK,CAAC,QAAQ,CAAC,SAAiB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,CAAC;QACzC,CAAC;QACD,OAAO,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;AAtKD,oDAsKC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type EvmAddress = string;
|
|
2
|
+
type GatewayQuote = {
|
|
3
|
+
onramp_address: EvmAddress;
|
|
4
|
+
dust_threshold: number;
|
|
5
|
+
satoshis: number;
|
|
6
|
+
fee: number;
|
|
7
|
+
gratuity: string;
|
|
8
|
+
bitcoin_address: string;
|
|
9
|
+
tx_proof_difficulty_factor: number;
|
|
10
|
+
};
|
|
11
|
+
type GatewayOrderResponse = {
|
|
12
|
+
onramp_address: EvmAddress;
|
|
13
|
+
token_address: EvmAddress;
|
|
14
|
+
txid: string;
|
|
15
|
+
status: boolean;
|
|
16
|
+
timestamp: number;
|
|
17
|
+
tokens: string;
|
|
18
|
+
satoshis: number;
|
|
19
|
+
fee: number;
|
|
20
|
+
tx_proof_difficulty_factor: number;
|
|
21
|
+
};
|
|
22
|
+
export declare class GatewayApiClient {
|
|
23
|
+
private baseUrl;
|
|
24
|
+
constructor(baseUrl: string);
|
|
25
|
+
getQuote(address: string, atomicAmount?: number | string): Promise<GatewayQuote>;
|
|
26
|
+
createOrder(contractAddress: string, userAddress: EvmAddress, atomicAmount: number | string): Promise<string>;
|
|
27
|
+
updateOrder(id: string, tx: string): Promise<void>;
|
|
28
|
+
getOrders(userAddress: EvmAddress): Promise<GatewayOrderResponse[]>;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
package/dist/gateway.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GatewayApiClient = void 0;
|
|
4
|
+
class GatewayApiClient {
|
|
5
|
+
constructor(baseUrl) {
|
|
6
|
+
this.baseUrl = baseUrl;
|
|
7
|
+
}
|
|
8
|
+
async getQuote(address, atomicAmount) {
|
|
9
|
+
const response = await fetch(`${this.baseUrl}/quote/${address}/${atomicAmount || ''}`, {
|
|
10
|
+
headers: {
|
|
11
|
+
'Content-Type': 'application/json',
|
|
12
|
+
Accept: 'application/json'
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
return await response.json();
|
|
16
|
+
}
|
|
17
|
+
async createOrder(contractAddress, userAddress, atomicAmount) {
|
|
18
|
+
const response = await fetch(`${this.baseUrl}/order`, {
|
|
19
|
+
method: 'POST',
|
|
20
|
+
headers: {
|
|
21
|
+
'Content-Type': 'application/json',
|
|
22
|
+
Accept: 'application/json'
|
|
23
|
+
},
|
|
24
|
+
body: JSON.stringify({ onramp_address: contractAddress, user_address: userAddress, satoshis: atomicAmount })
|
|
25
|
+
});
|
|
26
|
+
if (!response.ok) {
|
|
27
|
+
throw new Error('Failed to create order');
|
|
28
|
+
}
|
|
29
|
+
return await response.json();
|
|
30
|
+
}
|
|
31
|
+
async updateOrder(id, tx) {
|
|
32
|
+
const response = await fetch(`${this.baseUrl}/order/${id}`, {
|
|
33
|
+
method: 'PATCH',
|
|
34
|
+
headers: {
|
|
35
|
+
'Content-Type': 'application/json',
|
|
36
|
+
Accept: 'application/json'
|
|
37
|
+
},
|
|
38
|
+
body: JSON.stringify({ bitcoin_tx: tx })
|
|
39
|
+
});
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
throw new Error('Failed to update order');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async getOrders(userAddress) {
|
|
45
|
+
const response = await fetch(`${this.baseUrl}/orders/${userAddress}`, {
|
|
46
|
+
method: 'GET',
|
|
47
|
+
headers: {
|
|
48
|
+
'Content-Type': 'application/json',
|
|
49
|
+
Accept: 'application/json'
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return response.json();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.GatewayApiClient = GatewayApiClient;
|
|
56
|
+
//# sourceMappingURL=gateway.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway.js","sourceRoot":"","sources":["../src/gateway.ts"],"names":[],"mappings":";;;AAwBA,MAAa,gBAAgB;IAGzB,YAAY,OAAe;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAe,EAAE,YAA8B;QAC1D,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,UAAU,OAAO,IAAI,YAAY,IAAI,EAAE,EAAE,EAAE;YACnF,OAAO,EAAE;gBACL,cAAc,EAAE,kBAAkB;gBAClC,MAAM,EAAE,kBAAkB;aAC7B;SACJ,CAAC,CAAC;QAEH,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACjC,CAAC;IAGD,KAAK,CAAC,WAAW,CAAC,eAAuB,EAAE,WAAuB,EAAE,YAA6B;QAC7F,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,QAAQ,EAAE;YAClD,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACL,cAAc,EAAE,kBAAkB;gBAClC,MAAM,EAAE,kBAAkB;aAC7B;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC;SAC/G,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC9C,CAAC;QAED,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,EAAU,EAAE,EAAU;QACpC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,UAAU,EAAE,EAAE,EAAE;YACxD,MAAM,EAAE,OAAO;YACf,OAAO,EAAE;gBACL,cAAc,EAAE,kBAAkB;gBAClC,MAAM,EAAE,kBAAkB;aAC7B;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC;SAC3C,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC9C,CAAC;IACL,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,WAAuB;QACnC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,WAAW,WAAW,EAAE,EAAE;YAClE,MAAM,EAAE,KAAK;YACb,OAAO,EAAE;gBACL,cAAc,EAAE,kBAAkB;gBAClC,MAAM,EAAE,kBAAkB;aAC7B;SACJ,CAAC,CAAC;QAEH,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC3B,CAAC;CACJ;AA9DD,4CA8DC"}
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EsploraClient } from "./esplora";
|
|
2
2
|
import { OrdinalsClient } from "./ordinal-api";
|
|
3
|
-
export declare function getInscriptionIds(
|
|
3
|
+
export declare function getInscriptionIds(esploraClient: EsploraClient, ordinalsClient: OrdinalsClient, bitcoinAddress: string): Promise<string[]>;
|
package/dist/helpers.js
CHANGED
|
@@ -23,26 +23,25 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.getInscriptionIds =
|
|
26
|
+
exports.getInscriptionIds = getInscriptionIds;
|
|
27
27
|
const inscription_1 = require("./inscription");
|
|
28
28
|
const ordinal_api_1 = require("./ordinal-api");
|
|
29
29
|
const bitcoin = __importStar(require("bitcoinjs-lib"));
|
|
30
|
-
async function getInscriptionIds(
|
|
31
|
-
const utxos = await
|
|
30
|
+
async function getInscriptionIds(esploraClient, ordinalsClient, bitcoinAddress) {
|
|
31
|
+
const utxos = await esploraClient.getAddressUtxos(bitcoinAddress);
|
|
32
32
|
const inscriptionIds = await Promise.all(utxos.sort((a, b) => {
|
|
33
33
|
const heightA = a.height || Number.MAX_SAFE_INTEGER;
|
|
34
34
|
const heightB = b.height || Number.MAX_SAFE_INTEGER;
|
|
35
35
|
return heightA - heightB;
|
|
36
|
-
}).map(utxo => getInscriptionIdsForUtxo(
|
|
36
|
+
}).map(utxo => getInscriptionIdsForUtxo(esploraClient, ordinalsClient, utxo)));
|
|
37
37
|
return inscriptionIds.flat();
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
async function getInscriptionIdsForUtxo(electrsClient, ordinalsClient, utxo) {
|
|
39
|
+
async function getInscriptionIdsForUtxo(esploraClient, ordinalsClient, utxo) {
|
|
41
40
|
if (utxo.confirmed) {
|
|
42
41
|
const outputJson = await ordinalsClient.getInscriptionsFromOutPoint(utxo);
|
|
43
42
|
return outputJson.inscriptions;
|
|
44
43
|
}
|
|
45
|
-
const txHex = await
|
|
44
|
+
const txHex = await esploraClient.getTransactionHex(utxo.txid);
|
|
46
45
|
const tx = bitcoin.Transaction.fromHex(txHex);
|
|
47
46
|
if (utxo.vout == 0) {
|
|
48
47
|
const parentInscriptions = await Promise.all(tx.ins.map(async (txInput) => {
|
package/dist/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources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,CAAC,IAAI,IAAI,CAAC,EAAE,CAAC;QAKjB,MAAM,kBAAkB,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAC,OAAO,EAAC,EAAE;YACpE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACpD,MAAM,UAAU,GAAG,MAAM,cAAc,CAAC,2BAA2B,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;YACnG,OAAO,UAAU,CAAC,YAAY,CAAC;QACnC,CAAC,CAAC,CAAC,CAAC;QACJ,MAAM,cAAc,GAAG,kBAAkB,CAAC,IAAI,EAAE,CAAC;QACjD,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5B,OAAO,cAAc,CAAC;QAC1B,CAAC;IACL,CAAC;IAGD,MAAM,YAAY,GAAG,IAAA,+BAAiB,EAAC,EAAE,CAAC,CAAC;IAE3C,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,EAAE,CAAC;QACjB,OAAO,EAAE,CAAC;IACd,CAAC;SAAM,CAAC;QAEJ,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,2BAAa,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IAC9F,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,9 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./esplora"), exports);
|
|
18
18
|
__exportStar(require("./relay"), exports);
|
|
19
19
|
__exportStar(require("./utils"), exports);
|
|
20
20
|
__exportStar(require("./ordinals"), exports);
|
|
21
21
|
__exportStar(require("./helpers"), exports);
|
|
22
|
+
__exportStar(require("./wallet"), exports);
|
|
23
|
+
__exportStar(require("./gateway"), exports);
|
|
22
24
|
//# 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;AACxB,6CAA2B;AAC3B,4CAA0B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,0CAAwB;AACxB,0CAAwB;AACxB,6CAA2B;AAC3B,4CAA0B;AAC1B,2CAAyB;AACzB,4CAA0B"}
|
package/dist/inscription.d.ts
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import * as bitcoin from "bitcoinjs-lib";
|
|
3
|
-
import {
|
|
2
|
+
import { EsploraClient } from "./esplora";
|
|
4
3
|
export declare const PROTOCOL_ID: Buffer;
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export declare const MAX_CHUNK_SIZE = 520;
|
|
5
|
+
export declare function chunkContent(data: Buffer): Buffer[];
|
|
6
|
+
export declare class Inscription {
|
|
7
|
+
tags: Map<number, Buffer>;
|
|
8
|
+
body: Buffer;
|
|
9
|
+
constructor(tags?: Map<number, Buffer>, body?: Buffer);
|
|
10
|
+
getContentType(): string | null;
|
|
11
|
+
getContentEncoding(): string | null;
|
|
12
|
+
setContentType(contentType: string): void;
|
|
13
|
+
setContentEncoding(contentEncoding: string): void;
|
|
14
|
+
private getTags;
|
|
15
|
+
toScript(xOnlyPublicKey: Buffer): (number | Buffer)[];
|
|
7
16
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
17
|
+
export declare namespace Inscription {
|
|
18
|
+
function createTextInscription(text: string): Inscription;
|
|
19
|
+
function createInscription(contentType: string, content: Buffer): Inscription;
|
|
11
20
|
}
|
|
12
|
-
export declare function getContentType(inscription: Inscription): string | null;
|
|
13
|
-
export declare function getContentEncoding(inscription: Inscription): string | null;
|
|
14
21
|
export declare function parseInscriptions(tx: bitcoin.Transaction): Inscription[];
|
|
15
|
-
export declare function getTxInscriptions(
|
|
16
|
-
export declare function getInscriptionFromId(
|
|
17
|
-
export {};
|
|
22
|
+
export declare function getTxInscriptions(esploraClient: EsploraClient, txid: string): Promise<Inscription[]>;
|
|
23
|
+
export declare function getInscriptionFromId(esploraClient: EsploraClient, inscriptionId: string): Promise<Inscription>;
|
package/dist/inscription.js
CHANGED
|
@@ -23,13 +23,98 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.Inscription = exports.MAX_CHUNK_SIZE = exports.PROTOCOL_ID = void 0;
|
|
27
|
+
exports.chunkContent = chunkContent;
|
|
28
|
+
exports.parseInscriptions = parseInscriptions;
|
|
29
|
+
exports.getTxInscriptions = getTxInscriptions;
|
|
30
|
+
exports.getInscriptionFromId = getInscriptionFromId;
|
|
27
31
|
const bitcoin = __importStar(require("bitcoinjs-lib"));
|
|
28
32
|
const ordinal_api_1 = require("./ordinal-api");
|
|
33
|
+
const textEncoder = new TextEncoder();
|
|
34
|
+
const OP_INT_BASE = bitcoin.opcodes.OP_RESERVED;
|
|
29
35
|
const TAPROOT_ANNEX_PREFIX = 0x50;
|
|
30
36
|
exports.PROTOCOL_ID = Buffer.from("6f7264", "hex");
|
|
31
37
|
const CONTENT_TYPE_TAG = bitcoin.opcodes.OP_1;
|
|
32
38
|
const CONTENT_ENCODING_TAG = bitcoin.opcodes.OP_9;
|
|
39
|
+
exports.MAX_CHUNK_SIZE = 520;
|
|
40
|
+
function chunkContent(data) {
|
|
41
|
+
const body = [];
|
|
42
|
+
let start = 0;
|
|
43
|
+
while (start < data.length) {
|
|
44
|
+
body.push(data.subarray(start, start + exports.MAX_CHUNK_SIZE));
|
|
45
|
+
start += exports.MAX_CHUNK_SIZE;
|
|
46
|
+
}
|
|
47
|
+
return body;
|
|
48
|
+
}
|
|
49
|
+
function convertOpInt(value) {
|
|
50
|
+
if (value >= bitcoin.opcodes.OP_1 && value <= bitcoin.opcodes.OP_16) {
|
|
51
|
+
return value - OP_INT_BASE;
|
|
52
|
+
}
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
class Inscription {
|
|
56
|
+
constructor(tags, body) {
|
|
57
|
+
this.tags = tags ?? new Map();
|
|
58
|
+
this.body = body;
|
|
59
|
+
}
|
|
60
|
+
getContentType() {
|
|
61
|
+
const data = this.tags[CONTENT_TYPE_TAG];
|
|
62
|
+
if (Buffer.isBuffer(data)) {
|
|
63
|
+
return data.toString("utf-8");
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
getContentEncoding() {
|
|
68
|
+
const data = this.tags[CONTENT_ENCODING_TAG];
|
|
69
|
+
if (Buffer.isBuffer(data)) {
|
|
70
|
+
return data.toString("utf-8");
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
setContentType(contentType) {
|
|
75
|
+
this.tags[CONTENT_TYPE_TAG] = Buffer.from(textEncoder.encode(contentType));
|
|
76
|
+
}
|
|
77
|
+
setContentEncoding(contentEncoding) {
|
|
78
|
+
this.tags[CONTENT_ENCODING_TAG] = Buffer.from(textEncoder.encode(contentEncoding));
|
|
79
|
+
}
|
|
80
|
+
getTags() {
|
|
81
|
+
const tags = this.tags;
|
|
82
|
+
return Object.keys(this.tags).map(function (key) {
|
|
83
|
+
return [convertOpInt(Number(key)), tags[key]];
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
toScript(xOnlyPublicKey) {
|
|
87
|
+
return [
|
|
88
|
+
xOnlyPublicKey,
|
|
89
|
+
bitcoin.opcodes.OP_CHECKSIG,
|
|
90
|
+
bitcoin.opcodes.OP_0,
|
|
91
|
+
bitcoin.opcodes.OP_IF,
|
|
92
|
+
exports.PROTOCOL_ID,
|
|
93
|
+
...this.getTags().map(([key, value]) => [
|
|
94
|
+
1,
|
|
95
|
+
key,
|
|
96
|
+
value,
|
|
97
|
+
]).flat(),
|
|
98
|
+
bitcoin.opcodes.OP_0,
|
|
99
|
+
...chunkContent(this.body),
|
|
100
|
+
bitcoin.opcodes.OP_ENDIF,
|
|
101
|
+
];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.Inscription = Inscription;
|
|
105
|
+
(function (Inscription) {
|
|
106
|
+
function createTextInscription(text) {
|
|
107
|
+
return Inscription.createInscription("text/plain;charset=utf-8", Buffer.from(textEncoder.encode(text)));
|
|
108
|
+
}
|
|
109
|
+
Inscription.createTextInscription = createTextInscription;
|
|
110
|
+
function createInscription(contentType, content) {
|
|
111
|
+
const inscription = new Inscription;
|
|
112
|
+
inscription.setContentType(contentType);
|
|
113
|
+
inscription.body = content;
|
|
114
|
+
return inscription;
|
|
115
|
+
}
|
|
116
|
+
Inscription.createInscription = createInscription;
|
|
117
|
+
})(Inscription || (exports.Inscription = Inscription = {}));
|
|
33
118
|
function getTapscript(witness) {
|
|
34
119
|
const len = witness.length;
|
|
35
120
|
const last = witness[len - 1];
|
|
@@ -45,23 +130,6 @@ function getTapscript(witness) {
|
|
|
45
130
|
}
|
|
46
131
|
return bitcoin.script.decompile(witness[len - scriptPosFromLast]);
|
|
47
132
|
}
|
|
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
133
|
function parseInscriptions(tx) {
|
|
66
134
|
let inscriptions = [];
|
|
67
135
|
for (const txInput of tx.ins) {
|
|
@@ -81,12 +149,12 @@ function parseInscriptions(tx) {
|
|
|
81
149
|
if (!Buffer.isBuffer(data) && !data.equals(exports.PROTOCOL_ID)) {
|
|
82
150
|
continue;
|
|
83
151
|
}
|
|
84
|
-
let tags =
|
|
152
|
+
let tags = new Map();
|
|
85
153
|
let body = [];
|
|
86
154
|
let isBody = false;
|
|
87
155
|
for (let chunk = chunks.next(); !chunk.done; chunk = chunks.next()) {
|
|
88
156
|
if (chunk.value == bitcoin.opcodes.OP_ENDIF) {
|
|
89
|
-
inscriptions.push(
|
|
157
|
+
inscriptions.push(new Inscription(tags, Buffer.concat(body)));
|
|
90
158
|
break;
|
|
91
159
|
}
|
|
92
160
|
else if (chunk.value == bitcoin.opcodes.OP_0) {
|
|
@@ -107,17 +175,14 @@ function parseInscriptions(tx) {
|
|
|
107
175
|
}
|
|
108
176
|
return inscriptions;
|
|
109
177
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const txHex = await electrsClient.getTransactionHex(txid);
|
|
178
|
+
async function getTxInscriptions(esploraClient, txid) {
|
|
179
|
+
const txHex = await esploraClient.getTransactionHex(txid);
|
|
113
180
|
const tx = bitcoin.Transaction.fromHex(txHex);
|
|
114
181
|
return parseInscriptions(tx);
|
|
115
182
|
}
|
|
116
|
-
|
|
117
|
-
async function getInscriptionFromId(electrsClient, inscriptionId) {
|
|
183
|
+
async function getInscriptionFromId(esploraClient, inscriptionId) {
|
|
118
184
|
const { txid, index } = ordinal_api_1.InscriptionId.fromString(inscriptionId);
|
|
119
|
-
const inscriptions = await getTxInscriptions(
|
|
185
|
+
const inscriptions = await getTxInscriptions(esploraClient, txid);
|
|
120
186
|
return inscriptions[index];
|
|
121
187
|
}
|
|
122
|
-
exports.getInscriptionFromId = getInscriptionFromId;
|
|
123
188
|
//# sourceMappingURL=inscription.js.map
|
package/dist/inscription.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inscription.js","sourceRoot":"","sources":["../src/inscription.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"inscription.js","sourceRoot":"","sources":["../src/inscription.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,oCAQC;AA4GD,8CAmDC;AAED,8CAIC;AAED,oDAIC;AAvMD,uDAAyC;AAEzC,+CAA8C;AAE9C,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AAEtC,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC;AAGhD,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAGrB,QAAA,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;AAExD,MAAM,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;AAC9C,MAAM,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;AAGrC,QAAA,cAAc,GAAG,GAAG,CAAC;AAElC,SAAgB,YAAY,CAAC,IAAY;IACrC,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,OAAO,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QACzB,IAAI,CAAC,IAA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