@omnity/ree-client-ts-sdk 0.6.1 → 0.6.2
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/package.json +1 -4
- package/patches/runelib+1.0.7.patch +0 -857
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnity/ree-client-ts-sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "A TypeScript SDK for interacting with the Ree protocol on Bitcoin",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bitcoin",
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
},
|
|
23
23
|
"files": [
|
|
24
24
|
"dist",
|
|
25
|
-
"patches",
|
|
26
25
|
"README.md",
|
|
27
26
|
"LICENSE"
|
|
28
27
|
],
|
|
@@ -67,7 +66,6 @@
|
|
|
67
66
|
"test": "vitest",
|
|
68
67
|
"test:ui": "vitest --ui",
|
|
69
68
|
"coverage": "vitest run --coverage",
|
|
70
|
-
"postinstall": "patch-package",
|
|
71
69
|
"prepublishOnly": "npm run test && npm run build",
|
|
72
70
|
"publish:beta": "npm publish --tag beta",
|
|
73
71
|
"publish:latest": "npm publish"
|
|
@@ -99,7 +97,6 @@
|
|
|
99
97
|
"decimal.js": "^10.6.0",
|
|
100
98
|
"graphql": "^16.11.0",
|
|
101
99
|
"graphql-request": "^7.2.0",
|
|
102
|
-
"patch-package": "^8.0.1",
|
|
103
100
|
"runelib": "^1.0.7"
|
|
104
101
|
}
|
|
105
102
|
}
|
|
@@ -1,857 +0,0 @@
|
|
|
1
|
-
diff --git a/node_modules/runelib/dist/runestones.js b/node_modules/runelib/dist/runestones.js
|
|
2
|
-
index 11888bd..5930682 100644
|
|
3
|
-
--- a/node_modules/runelib/dist/runestones.js
|
|
4
|
-
+++ b/node_modules/runelib/dist/runestones.js
|
|
5
|
-
@@ -219,22 +219,22 @@ class Runestone {
|
|
6
|
-
let pushNum;
|
|
7
|
-
if (msgBuff.length < 0x4c) {
|
|
8
|
-
pushNum = Buffer.alloc(1);
|
|
9
|
-
- pushNum.writeUint8(msgBuff.length);
|
|
10
|
-
+ pushNum.writeUInt8(msgBuff.length);
|
|
11
|
-
}
|
|
12
|
-
else if (msgBuff.length < 0x100) {
|
|
13
|
-
pushNum = Buffer.alloc(2);
|
|
14
|
-
- pushNum.writeUint8(0x4c);
|
|
15
|
-
- pushNum.writeUint8(msgBuff.length);
|
|
16
|
-
+ pushNum.writeUInt8(0x4c);
|
|
17
|
-
+ pushNum.writeUInt8(msgBuff.length);
|
|
18
|
-
}
|
|
19
|
-
else if (msgBuff.length < 0x10000) {
|
|
20
|
-
pushNum = Buffer.alloc(3);
|
|
21
|
-
- pushNum.writeUint8(0x4d);
|
|
22
|
-
- pushNum.writeUint16LE(msgBuff.length);
|
|
23
|
-
+ pushNum.writeUInt8(0x4d);
|
|
24
|
-
+ pushNum.writeUInt16LE(msgBuff.length);
|
|
25
|
-
}
|
|
26
|
-
else if (msgBuff.length < 0x100000000) {
|
|
27
|
-
pushNum = Buffer.alloc(5);
|
|
28
|
-
- pushNum.writeUint8(0x4e);
|
|
29
|
-
- pushNum.writeUint32LE(msgBuff.length);
|
|
30
|
-
+ pushNum.writeUInt8(0x4e);
|
|
31
|
-
+ pushNum.writeUInt32LE(msgBuff.length);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
throw new Error("runestone too big!");
|
|
35
|
-
@@ -643,7 +643,7 @@ class EtchInscription {
|
|
36
|
-
const val = ls[i + 1];
|
|
37
|
-
if (typeof val == 'number') {
|
|
38
|
-
const buff = Buffer.alloc(1);
|
|
39
|
-
- buff.writeUint8(val);
|
|
40
|
-
+ buff.writeUInt8(val);
|
|
41
|
-
fields.set(tag, buff);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
diff --git a/node_modules/runelib/dist/runestones.js.bak b/node_modules/runelib/dist/runestones.js.bak
|
|
45
|
-
new file mode 100644
|
|
46
|
-
index 0000000..52eebf0
|
|
47
|
-
--- /dev/null
|
|
48
|
-
+++ b/node_modules/runelib/dist/runestones.js.bak
|
|
49
|
-
@@ -0,0 +1,705 @@
|
|
50
|
-
+"use strict";
|
|
51
|
-
+Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
|
-
+exports.EtchInscription = exports.Message = exports.Runestone = exports.Etching = exports.Rune = exports.Terms = exports.Range = exports.Flaw = exports.Tag = exports.Flag = exports.Edict = exports.RuneId = void 0;
|
|
53
|
-
+const bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
|
54
|
-
+const base26_1 = require("./base26");
|
|
55
|
-
+const fts_1 = require("./fts");
|
|
56
|
-
+const leb128_1 = require("./leb128");
|
|
57
|
-
+const utils_1 = require("./utils");
|
|
58
|
-
+const spacers_1 = require("./spacers");
|
|
59
|
-
+/**
|
|
60
|
-
+ * Rune IDs are represented in text as BLOCK:TX.
|
|
61
|
-
+ */
|
|
62
|
-
+class RuneId {
|
|
63
|
-
+ constructor(block, idx) {
|
|
64
|
-
+ this.block = block;
|
|
65
|
-
+ this.idx = idx;
|
|
66
|
-
+ }
|
|
67
|
-
+ next(block, idx) {
|
|
68
|
-
+ if (block > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
69
|
-
+ return (0, fts_1.none)();
|
|
70
|
-
+ }
|
|
71
|
-
+ if (idx > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
72
|
-
+ return (0, fts_1.none)();
|
|
73
|
-
+ }
|
|
74
|
-
+ let b = BigInt(this.block) + block;
|
|
75
|
-
+ if (b > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
76
|
-
+ return (0, fts_1.none)();
|
|
77
|
-
+ }
|
|
78
|
-
+ let i = block === 0n ? BigInt(this.idx) + idx : idx;
|
|
79
|
-
+ if (i > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
80
|
-
+ return (0, fts_1.none)();
|
|
81
|
-
+ }
|
|
82
|
-
+ return (0, fts_1.some)(new RuneId(Number(b), Number(i)));
|
|
83
|
-
+ }
|
|
84
|
-
+}
|
|
85
|
-
+exports.RuneId = RuneId;
|
|
86
|
-
+/**
|
|
87
|
-
+ * Rune ID block heights and transaction indices in edicts are delta encoded.
|
|
88
|
-
+ * Edict rune ID decoding starts with a base block height and transaction index of zero.
|
|
89
|
-
+ * When decoding each rune ID, first the encoded block height delta is added to the base block height.
|
|
90
|
-
+ * If the block height delta is zero, the next integer is a transaction index delta.
|
|
91
|
-
+ * If the block height delta is greater than zero, the next integer is instead an absolute transaction index.
|
|
92
|
-
+ */
|
|
93
|
-
+class Edict {
|
|
94
|
-
+ constructor(id, amount, output) {
|
|
95
|
-
+ this.id = id;
|
|
96
|
-
+ this.amount = amount;
|
|
97
|
-
+ this.output = output;
|
|
98
|
-
+ }
|
|
99
|
-
+ static from_integers(tx, id, amount, output) {
|
|
100
|
-
+ if (output > 4294967295n || output < 0n) {
|
|
101
|
-
+ return (0, fts_1.none)();
|
|
102
|
-
+ }
|
|
103
|
-
+ if (Number(output) > tx.outs.length) {
|
|
104
|
-
+ return (0, fts_1.none)();
|
|
105
|
-
+ }
|
|
106
|
-
+ return (0, fts_1.some)(new Edict(id, amount, Number(output)));
|
|
107
|
-
+ }
|
|
108
|
-
+}
|
|
109
|
-
+exports.Edict = Edict;
|
|
110
|
-
+var Flag;
|
|
111
|
-
+(function (Flag) {
|
|
112
|
-
+ /** The Etching flag marks this transaction as containing an etching. */
|
|
113
|
-
+ Flag[Flag["Etching"] = 0] = "Etching";
|
|
114
|
-
+ /** The Terms flag marks this transaction's etching as having open mint terms. */
|
|
115
|
-
+ Flag[Flag["Terms"] = 1] = "Terms";
|
|
116
|
-
+ /** The Turbo flag marks this transaction's etching as opting into future protocol changes. These protocol changes may increase light client validation costs, or just be highly degenerate. */
|
|
117
|
-
+ Flag[Flag["Turbo"] = 2] = "Turbo";
|
|
118
|
-
+ /** The Cenotaph flag is unrecognized. */
|
|
119
|
-
+ Flag[Flag["Cenotaph"] = 127] = "Cenotaph";
|
|
120
|
-
+})(Flag || (exports.Flag = Flag = {}));
|
|
121
|
-
+var Tag;
|
|
122
|
-
+(function (Tag) {
|
|
123
|
-
+ /** The Body tag marks the end of the runestone's fields, causing all following integers to be interpreted as edicts. */
|
|
124
|
-
+ Tag[Tag["Body"] = 0] = "Body";
|
|
125
|
-
+ /** The Flag field contains a bitmap of flags, whose position is 1 << FLAG_VALUE: */
|
|
126
|
-
+ Tag[Tag["Flags"] = 2] = "Flags";
|
|
127
|
-
+ /** The Rune field contains the name of the rune being etched. If the Etching flag is set but the Rune field is omitted, a reserved rune name is allocated. */
|
|
128
|
-
+ Tag[Tag["Rune"] = 4] = "Rune";
|
|
129
|
-
+ /** The Premine field contains the amount of premined runes. */
|
|
130
|
-
+ Tag[Tag["Premine"] = 6] = "Premine";
|
|
131
|
-
+ /** The Cap field contains the allowed number of mints. */
|
|
132
|
-
+ Tag[Tag["Cap"] = 8] = "Cap";
|
|
133
|
-
+ /** The Amount field contains the amount of runes each mint transaction receives. */
|
|
134
|
-
+ Tag[Tag["Amount"] = 10] = "Amount";
|
|
135
|
-
+ /** The HeightStart and HeightEnd fields contain the mint's starting and ending absolute block heights, respectively. The mint is open starting in the block with height HeightStart, and closes in the block with height HeightEnd. */
|
|
136
|
-
+ Tag[Tag["HeightStart"] = 12] = "HeightStart";
|
|
137
|
-
+ Tag[Tag["HeightEnd"] = 14] = "HeightEnd";
|
|
138
|
-
+ /** The OffsetStart and OffsetEnd fields contain the mint's starting and ending block heights, relative to the block in which the etching is mined. The mint is open starting in the block with height OffsetStart + ETCHING_HEIGHT, and closes in the block with height OffsetEnd + ETCHING_HEIGHT. */
|
|
139
|
-
+ Tag[Tag["OffsetStart"] = 16] = "OffsetStart";
|
|
140
|
-
+ Tag[Tag["OffsetEnd"] = 18] = "OffsetEnd";
|
|
141
|
-
+ /** The Mint field contains the Rune ID of the rune to be minted in this transaction. */
|
|
142
|
-
+ Tag[Tag["Mint"] = 20] = "Mint";
|
|
143
|
-
+ /** The Pointer field contains the index of the output to which runes unallocated by edicts should be transferred. If the Pointer field is absent, unallocated runes are transferred to the first non-OP_RETURN output. */
|
|
144
|
-
+ Tag[Tag["Pointer"] = 22] = "Pointer";
|
|
145
|
-
+ /** The Cenotaph field is unrecognized. */
|
|
146
|
-
+ Tag[Tag["Cenotaph"] = 126] = "Cenotaph";
|
|
147
|
-
+ /** The Divisibility field, raised to the power of ten, is the number of subunits in a super unit of runes. */
|
|
148
|
-
+ Tag[Tag["Divisibility"] = 1] = "Divisibility";
|
|
149
|
-
+ /** The Spacers field is a bitfield of • spacers that should be displayed between the letters of the rune's name. Trailing spacers are ignored. */
|
|
150
|
-
+ Tag[Tag["Spacers"] = 3] = "Spacers";
|
|
151
|
-
+ /** The Symbol field is the Unicode codepoint of the Rune's currency symbol,
|
|
152
|
-
+ * which should be displayed after amounts of that rune. If a rune does not have a currency symbol,
|
|
153
|
-
+ * the generic currency character ¤ should be used.
|
|
154
|
-
+ * For example, if the Symbol is # and the divisibility is 2,
|
|
155
|
-
+ * the amount of 1234 units should be displayed as 12.34 #.
|
|
156
|
-
+ */
|
|
157
|
-
+ Tag[Tag["Symbol"] = 5] = "Symbol";
|
|
158
|
-
+ /** The Nop field is unrecognized. */
|
|
159
|
-
+ Tag[Tag["Nop"] = 127] = "Nop";
|
|
160
|
-
+})(Tag || (exports.Tag = Tag = {}));
|
|
161
|
-
+var Flaw;
|
|
162
|
-
+(function (Flaw) {
|
|
163
|
-
+ Flaw[Flaw["EdictOutput"] = 0] = "EdictOutput";
|
|
164
|
-
+ Flaw[Flaw["EdictRuneId"] = 1] = "EdictRuneId";
|
|
165
|
-
+ Flaw[Flaw["InvalidScript"] = 2] = "InvalidScript";
|
|
166
|
-
+ Flaw[Flaw["Opcode"] = 3] = "Opcode";
|
|
167
|
-
+ Flaw[Flaw["SupplyOverflow"] = 4] = "SupplyOverflow";
|
|
168
|
-
+ Flaw[Flaw["TrailingIntegers"] = 5] = "TrailingIntegers";
|
|
169
|
-
+ Flaw[Flaw["TruncatedField"] = 6] = "TruncatedField";
|
|
170
|
-
+ Flaw[Flaw["UnrecognizedEvenTag"] = 7] = "UnrecognizedEvenTag";
|
|
171
|
-
+ Flaw[Flaw["UnrecognizedFlag"] = 8] = "UnrecognizedFlag";
|
|
172
|
-
+ Flaw[Flaw["Varint"] = 9] = "Varint";
|
|
173
|
-
+})(Flaw || (exports.Flaw = Flaw = {}));
|
|
174
|
-
+class Range {
|
|
175
|
-
+ constructor(start, end) {
|
|
176
|
-
+ this.start = start;
|
|
177
|
-
+ this.end = end;
|
|
178
|
-
+ }
|
|
179
|
-
+}
|
|
180
|
-
+exports.Range = Range;
|
|
181
|
-
+class Terms {
|
|
182
|
-
+ constructor(amount, cap, height, offset) {
|
|
183
|
-
+ this.amount = amount;
|
|
184
|
-
+ this.cap = cap;
|
|
185
|
-
+ this.height = height;
|
|
186
|
-
+ this.offset = offset;
|
|
187
|
-
+ }
|
|
188
|
-
+}
|
|
189
|
-
+exports.Terms = Terms;
|
|
190
|
-
+class Rune {
|
|
191
|
-
+ constructor(value) {
|
|
192
|
-
+ this.value = value;
|
|
193
|
-
+ }
|
|
194
|
-
+ get name() {
|
|
195
|
-
+ return Rune.toName(this.value);
|
|
196
|
-
+ }
|
|
197
|
-
+ static toName(s) {
|
|
198
|
-
+ return (0, base26_1.base26Decode)(s);
|
|
199
|
-
+ }
|
|
200
|
-
+ static fromName(name) {
|
|
201
|
-
+ return new Rune((0, base26_1.base26Encode)((0, spacers_1.removeSpacers)(name)));
|
|
202
|
-
+ }
|
|
203
|
-
+ toString() {
|
|
204
|
-
+ return this.name;
|
|
205
|
-
+ }
|
|
206
|
-
+}
|
|
207
|
-
+exports.Rune = Rune;
|
|
208
|
-
+class Etching {
|
|
209
|
-
+ constructor(divisibility, premine, rune, spacers, symbol, terms, turbo) {
|
|
210
|
-
+ this.divisibility = divisibility;
|
|
211
|
-
+ this.premine = premine;
|
|
212
|
-
+ this.rune = rune;
|
|
213
|
-
+ this.spacers = spacers;
|
|
214
|
-
+ this.symbol = symbol;
|
|
215
|
-
+ this.terms = terms;
|
|
216
|
-
+ this.turbo = turbo;
|
|
217
|
-
+ }
|
|
218
|
-
+}
|
|
219
|
-
+exports.Etching = Etching;
|
|
220
|
-
+Etching.MAX_DIVISIBILITY = 38;
|
|
221
|
-
+Etching.MAX_SPACERS = 134217727;
|
|
222
|
-
+class Runestone {
|
|
223
|
-
+ constructor(edicts = [], etching, mint, pointer) {
|
|
224
|
-
+ this.edicts = edicts;
|
|
225
|
-
+ this.etching = etching;
|
|
226
|
-
+ this.mint = mint;
|
|
227
|
-
+ this.pointer = pointer;
|
|
228
|
-
+ }
|
|
229
|
-
+ static create(json, type = 'etch') {
|
|
230
|
-
+ if (type === 'etch') {
|
|
231
|
-
+ json = json;
|
|
232
|
-
+ const runename = Rune.fromName(json.name);
|
|
233
|
-
+ const terms = new Terms(json.amount, json.cap, new Range(json.startHeight ? (0, fts_1.some)(json.startHeight) : (0, fts_1.none)(), json.endHeight ? (0, fts_1.some)(json.endHeight) : (0, fts_1.none)()), new Range(json.startOffset ? (0, fts_1.some)(json.startOffset) : (0, fts_1.none)(), json.endOffset ? (0, fts_1.some)(json.endOffset) : (0, fts_1.none)()));
|
|
234
|
-
+ const divisibility = json.divisibility ? (0, fts_1.some)(json.divisibility) : (0, fts_1.none)();
|
|
235
|
-
+ const premine = json.premine ? (0, fts_1.some)(json.premine) : (0, fts_1.none)();
|
|
236
|
-
+ const spacers = json.name.indexOf('•') > -1 ? (0, fts_1.some)((0, spacers_1.getSpacersVal)(json.name)) : (0, fts_1.none)();
|
|
237
|
-
+ const symbol = json.symbol ? (0, fts_1.some)(json.symbol) : (0, fts_1.none)();
|
|
238
|
-
+ const pointer = typeof json.pointer === 'number' ? (0, fts_1.some)(json.pointer) : (0, fts_1.none)();
|
|
239
|
-
+ const etching = new Etching(divisibility, premine, (0, fts_1.some)(runename), spacers, symbol, (0, fts_1.some)(terms), true);
|
|
240
|
-
+ return new Runestone([], (0, fts_1.some)(etching), (0, fts_1.none)(), pointer);
|
|
241
|
-
+ }
|
|
242
|
-
+ else if (type === 'mint') {
|
|
243
|
-
+ json = json;
|
|
244
|
-
+ const pointer = typeof json.pointer === 'number' ? (0, fts_1.some)(json.pointer) : (0, fts_1.none)();
|
|
245
|
-
+ return new Runestone([], (0, fts_1.none)(), (0, fts_1.some)(new RuneId(json.block, json.txIdx)), pointer);
|
|
246
|
-
+ }
|
|
247
|
-
+ else {
|
|
248
|
-
+ throw new Error(`not ${type} support now`);
|
|
249
|
-
+ }
|
|
250
|
-
+ }
|
|
251
|
-
+ static decipher(rawTx) {
|
|
252
|
-
+ const tx = bitcoinjs_lib_1.Transaction.fromHex(rawTx);
|
|
253
|
-
+ const payload = Runestone.payload(tx);
|
|
254
|
-
+ if (payload.isSome()) {
|
|
255
|
-
+ const integers = Runestone.integers(payload.value());
|
|
256
|
-
+ const message = Message.from_integers(tx, integers.value());
|
|
257
|
-
+ const etching = message.getEtching();
|
|
258
|
-
+ const mint = message.getMint();
|
|
259
|
-
+ const pointer = message.getPointer();
|
|
260
|
-
+ return (0, fts_1.some)(new Runestone(message.edicts, etching, mint, pointer));
|
|
261
|
-
+ }
|
|
262
|
-
+ return (0, fts_1.none)();
|
|
263
|
-
+ }
|
|
264
|
-
+ encipher() {
|
|
265
|
-
+ const msg = this.toMessage();
|
|
266
|
-
+ const msgBuff = msg.toBuffer();
|
|
267
|
-
+ const prefix = Buffer.from('6a5d', 'hex'); // OP_RETURN OP_13
|
|
268
|
-
+ let pushNum;
|
|
269
|
-
+ if (msgBuff.length < 0x4c) {
|
|
270
|
-
+ pushNum = Buffer.alloc(1);
|
|
271
|
-
+ pushNum.writeUInt8(msgBuff.length);
|
|
272
|
-
+ }
|
|
273
|
-
+ else if (msgBuff.length < 0x100) {
|
|
274
|
-
+ pushNum = Buffer.alloc(2);
|
|
275
|
-
+ pushNum.writeUInt8(0x4c);
|
|
276
|
-
+ pushNum.writeUInt8(msgBuff.length);
|
|
277
|
-
+ }
|
|
278
|
-
+ else if (msgBuff.length < 0x10000) {
|
|
279
|
-
+ pushNum = Buffer.alloc(3);
|
|
280
|
-
+ pushNum.writeUInt8(0x4d);
|
|
281
|
-
+ pushNum.writeUInt16LE(msgBuff.length);
|
|
282
|
-
+ }
|
|
283
|
-
+ else if (msgBuff.length < 0x100000000) {
|
|
284
|
-
+ pushNum = Buffer.alloc(5);
|
|
285
|
-
+ pushNum.writeUInt8(0x4e);
|
|
286
|
-
+ pushNum.writeUint32LE(msgBuff.length);
|
|
287
|
-
+ }
|
|
288
|
-
+ else {
|
|
289
|
-
+ throw new Error("runestone too big!");
|
|
290
|
-
+ }
|
|
291
|
-
+ return Buffer.concat([prefix, pushNum, msgBuff]);
|
|
292
|
-
+ }
|
|
293
|
-
+ static payload(tx) {
|
|
294
|
-
+ for (const output of tx.outs) {
|
|
295
|
-
+ //script.fromASM
|
|
296
|
-
+ const ls = bitcoinjs_lib_1.script.decompile(output.script);
|
|
297
|
-
+ if (ls[0] !== bitcoinjs_lib_1.script.OPS.OP_RETURN) {
|
|
298
|
-
+ continue;
|
|
299
|
-
+ }
|
|
300
|
-
+ if (ls[1] !== Runestone.MAGIC_NUMBER) {
|
|
301
|
-
+ continue;
|
|
302
|
-
+ }
|
|
303
|
-
+ for (let i = 2; i < ls.length; i++) {
|
|
304
|
-
+ const element = ls[i];
|
|
305
|
-
+ if (element instanceof Uint8Array) {
|
|
306
|
-
+ return (0, fts_1.some)(Array.from(element));
|
|
307
|
-
+ }
|
|
308
|
-
+ return (0, fts_1.none)();
|
|
309
|
-
+ }
|
|
310
|
-
+ return (0, fts_1.none)();
|
|
311
|
-
+ }
|
|
312
|
-
+ return (0, fts_1.none)();
|
|
313
|
-
+ }
|
|
314
|
-
+ static integers(payload) {
|
|
315
|
-
+ let integers = [];
|
|
316
|
-
+ let i = 0;
|
|
317
|
-
+ while (i < payload.length) {
|
|
318
|
-
+ let { n, len } = (0, leb128_1.decodeLEB128)(payload.slice(i));
|
|
319
|
-
+ integers.push(n);
|
|
320
|
-
+ i += len;
|
|
321
|
-
+ }
|
|
322
|
-
+ return (0, fts_1.some)(integers);
|
|
323
|
-
+ }
|
|
324
|
-
+ toMessage() {
|
|
325
|
-
+ let fields = new Map();
|
|
326
|
-
+ const etching = this.etching.value();
|
|
327
|
-
+ if (etching) {
|
|
328
|
-
+ let flags = 1;
|
|
329
|
-
+ if (etching.terms.isSome()) {
|
|
330
|
-
+ let mask = 1 << Flag.Terms;
|
|
331
|
-
+ flags |= mask;
|
|
332
|
-
+ }
|
|
333
|
-
+ if (etching.turbo) {
|
|
334
|
-
+ let mask = 1 << Flag.Turbo;
|
|
335
|
-
+ flags |= mask;
|
|
336
|
-
+ }
|
|
337
|
-
+ fields.set(Tag.Flags, [BigInt(flags)]);
|
|
338
|
-
+ const rune = etching.rune.value();
|
|
339
|
-
+ if (rune !== null) {
|
|
340
|
-
+ fields.set(Tag.Rune, [BigInt(rune.value)]);
|
|
341
|
-
+ }
|
|
342
|
-
+ const divisibility = etching.divisibility.value();
|
|
343
|
-
+ if (divisibility !== null) {
|
|
344
|
-
+ fields.set(Tag.Divisibility, [BigInt(divisibility)]);
|
|
345
|
-
+ }
|
|
346
|
-
+ const spacers = etching.spacers.value();
|
|
347
|
-
+ if (spacers !== null) {
|
|
348
|
-
+ fields.set(Tag.Spacers, [BigInt(spacers)]);
|
|
349
|
-
+ }
|
|
350
|
-
+ const symbol = etching.symbol.value();
|
|
351
|
-
+ if (symbol !== null) {
|
|
352
|
-
+ fields.set(Tag.Symbol, [BigInt(symbol.charCodeAt(0))]);
|
|
353
|
-
+ }
|
|
354
|
-
+ const premine = etching.premine.value();
|
|
355
|
-
+ if (premine !== null) {
|
|
356
|
-
+ fields.set(Tag.Premine, [BigInt(premine)]);
|
|
357
|
-
+ }
|
|
358
|
-
+ const terms = etching.terms.value();
|
|
359
|
-
+ if (terms !== null) {
|
|
360
|
-
+ fields.set(Tag.Amount, [BigInt(terms.amount)]);
|
|
361
|
-
+ fields.set(Tag.Cap, [BigInt(terms.cap)]);
|
|
362
|
-
+ const heightStart = terms.height.start.value();
|
|
363
|
-
+ if (heightStart) {
|
|
364
|
-
+ fields.set(Tag.HeightStart, [BigInt(heightStart)]);
|
|
365
|
-
+ }
|
|
366
|
-
+ const heightEnd = terms.height.end.value();
|
|
367
|
-
+ if (heightEnd) {
|
|
368
|
-
+ fields.set(Tag.HeightEnd, [BigInt(heightEnd)]);
|
|
369
|
-
+ }
|
|
370
|
-
+ const offsetStart = terms.offset.start.value();
|
|
371
|
-
+ if (offsetStart) {
|
|
372
|
-
+ fields.set(Tag.OffsetStart, [BigInt(offsetStart)]);
|
|
373
|
-
+ }
|
|
374
|
-
+ const offsetEnd = terms.offset.end.value();
|
|
375
|
-
+ if (offsetEnd) {
|
|
376
|
-
+ fields.set(Tag.OffsetEnd, [BigInt(offsetEnd)]);
|
|
377
|
-
+ }
|
|
378
|
-
+ }
|
|
379
|
-
+ }
|
|
380
|
-
+ const mint = this.mint.value();
|
|
381
|
-
+ if (mint !== null) {
|
|
382
|
-
+ fields.set(Tag.Mint, [BigInt(mint.block), BigInt(mint.idx)]);
|
|
383
|
-
+ }
|
|
384
|
-
+ const pointer = this.pointer.value();
|
|
385
|
-
+ if (pointer !== null) {
|
|
386
|
-
+ fields.set(Tag.Pointer, [BigInt(pointer)]);
|
|
387
|
-
+ }
|
|
388
|
-
+ return new Message(fields, this.edicts, 0);
|
|
389
|
-
+ }
|
|
390
|
-
+}
|
|
391
|
-
+exports.Runestone = Runestone;
|
|
392
|
-
+Runestone.MAGIC_NUMBER = 93;
|
|
393
|
-
+class Message {
|
|
394
|
-
+ constructor(fields = new Map(), edicts = [], flaws = 0) {
|
|
395
|
-
+ this.fields = fields;
|
|
396
|
-
+ this.edicts = edicts;
|
|
397
|
-
+ this.flaws = flaws;
|
|
398
|
-
+ }
|
|
399
|
-
+ static from_integers(tx, integers) {
|
|
400
|
-
+ let fields = new Map();
|
|
401
|
-
+ let edicts = [];
|
|
402
|
-
+ let flaws = 0;
|
|
403
|
-
+ let isBody = false;
|
|
404
|
-
+ for (let i = 0; i < integers.length;) {
|
|
405
|
-
+ let tag = integers[i];
|
|
406
|
-
+ if (Number(tag) === Tag.Body) {
|
|
407
|
-
+ isBody = true;
|
|
408
|
-
+ i += 1;
|
|
409
|
-
+ continue;
|
|
410
|
-
+ }
|
|
411
|
-
+ if (!isBody) {
|
|
412
|
-
+ // Fields:
|
|
413
|
-
+ let val = integers[i + 1];
|
|
414
|
-
+ const vals = fields.get(Number(tag)) || [];
|
|
415
|
-
+ vals.push(val);
|
|
416
|
-
+ fields.set(Number(tag), vals);
|
|
417
|
-
+ i += 2;
|
|
418
|
-
+ }
|
|
419
|
-
+ else {
|
|
420
|
-
+ // Edicts:
|
|
421
|
-
+ let id = new RuneId(0, 0);
|
|
422
|
-
+ for (const chunk of (0, utils_1.chunks)(integers.slice(i), 4)) {
|
|
423
|
-
+ if (chunk.length != 4) {
|
|
424
|
-
+ flaws |= Flaw.TrailingIntegers;
|
|
425
|
-
+ break;
|
|
426
|
-
+ }
|
|
427
|
-
+ let next = id.next(chunk[0], chunk[1]);
|
|
428
|
-
+ if (!next.isSome()) {
|
|
429
|
-
+ flaws |= Flaw.EdictRuneId;
|
|
430
|
-
+ break;
|
|
431
|
-
+ }
|
|
432
|
-
+ const edict = Edict.from_integers(tx, next.value(), chunk[2], chunk[3]);
|
|
433
|
-
+ if (!edict.isSome()) {
|
|
434
|
-
+ flaws |= Flaw.EdictOutput;
|
|
435
|
-
+ break;
|
|
436
|
-
+ }
|
|
437
|
-
+ id = next.value();
|
|
438
|
-
+ edicts.push(edict.value());
|
|
439
|
-
+ }
|
|
440
|
-
+ i += 4;
|
|
441
|
-
+ }
|
|
442
|
-
+ }
|
|
443
|
-
+ return new Message(fields, edicts, flaws);
|
|
444
|
-
+ }
|
|
445
|
-
+ addFieldVal(tag, val) {
|
|
446
|
-
+ const vals = this.fields.get(Number(tag)) || [];
|
|
447
|
-
+ vals.push(val);
|
|
448
|
-
+ this.fields.set(Number(tag), vals);
|
|
449
|
-
+ }
|
|
450
|
-
+ addEdict(edict) {
|
|
451
|
-
+ this.edicts.push(edict);
|
|
452
|
-
+ }
|
|
453
|
-
+ toBuffer() {
|
|
454
|
-
+ const buffArr = [];
|
|
455
|
-
+ // Serialize fields.
|
|
456
|
-
+ for (const [tag, vals] of this.fields) {
|
|
457
|
-
+ for (const val of vals) {
|
|
458
|
-
+ const tagBuff = Buffer.alloc(1);
|
|
459
|
-
+ tagBuff.writeUInt8(tag);
|
|
460
|
-
+ buffArr.push(tagBuff);
|
|
461
|
-
+ buffArr.push(Buffer.from((0, leb128_1.encodeLEB128)(val)));
|
|
462
|
-
+ }
|
|
463
|
-
+ }
|
|
464
|
-
+ // Serialize edicts.
|
|
465
|
-
+ if (this.edicts.length > 0) {
|
|
466
|
-
+ buffArr.push(Buffer.from('00', 'hex'));
|
|
467
|
-
+ // 1) Sort by block height
|
|
468
|
-
+ // 2) Sort by tx idx
|
|
469
|
-
+ this.edicts.sort((a, b) => {
|
|
470
|
-
+ if (a.id.block == b.id.block) {
|
|
471
|
-
+ return a.id.idx - b.id.idx;
|
|
472
|
-
+ }
|
|
473
|
-
+ return a.id.block - b.id.block;
|
|
474
|
-
+ });
|
|
475
|
-
+ // 3) Delta encode
|
|
476
|
-
+ let lastBlockHeight = 0n;
|
|
477
|
-
+ let lastTxIdx = 0n;
|
|
478
|
-
+ for (let i = 0; i < this.edicts.length; i++) {
|
|
479
|
-
+ const edict = this.edicts[i];
|
|
480
|
-
+ if (i == 0) {
|
|
481
|
-
+ lastBlockHeight = BigInt(edict.id.block);
|
|
482
|
-
+ lastTxIdx = BigInt(edict.id.idx);
|
|
483
|
-
+ buffArr.push(Buffer.from((0, leb128_1.encodeLEB128)(lastBlockHeight)));
|
|
484
|
-
+ buffArr.push(Buffer.from((0, leb128_1.encodeLEB128)(lastTxIdx)));
|
|
485
|
-
+ }
|
|
486
|
-
+ else {
|
|
487
|
-
+ const currBlockHeight = BigInt(edict.id.block);
|
|
488
|
-
+ const currTxIdx = BigInt(edict.id.idx);
|
|
489
|
-
+ if (currBlockHeight == lastBlockHeight) {
|
|
490
|
-
+ const deltaTxIdx = currTxIdx - lastTxIdx;
|
|
491
|
-
+ lastTxIdx = currTxIdx;
|
|
492
|
-
+ buffArr.push(Buffer.from((0, leb128_1.encodeLEB128)(0n)));
|
|
493
|
-
+ buffArr.push(Buffer.from((0, leb128_1.encodeLEB128)(deltaTxIdx)));
|
|
494
|
-
+ }
|
|
495
|
-
+ else {
|
|
496
|
-
+ const deltaBlockHeight = currBlockHeight - lastBlockHeight;
|
|
497
|
-
+ lastBlockHeight = currBlockHeight;
|
|
498
|
-
+ lastTxIdx = currTxIdx;
|
|
499
|
-
+ buffArr.push(Buffer.from((0, leb128_1.encodeLEB128)(deltaBlockHeight)));
|
|
500
|
-
+ buffArr.push(Buffer.from((0, leb128_1.encodeLEB128)(currTxIdx)));
|
|
501
|
-
+ }
|
|
502
|
-
+ }
|
|
503
|
-
+ buffArr.push(Buffer.from((0, leb128_1.encodeLEB128)(BigInt(edict.amount))));
|
|
504
|
-
+ buffArr.push(Buffer.from((0, leb128_1.encodeLEB128)(BigInt(edict.output))));
|
|
505
|
-
+ }
|
|
506
|
-
+ }
|
|
507
|
-
+ return Buffer.concat(buffArr);
|
|
508
|
-
+ }
|
|
509
|
-
+ getFlags() {
|
|
510
|
-
+ return Number(this.fields.get(Tag.Flags));
|
|
511
|
-
+ }
|
|
512
|
-
+ hasFlags(flag) {
|
|
513
|
-
+ const flags = this.getFlags();
|
|
514
|
-
+ const mask = 1 << flag;
|
|
515
|
-
+ return (flags & mask) != 0;
|
|
516
|
-
+ }
|
|
517
|
-
+ getMint() {
|
|
518
|
-
+ if (!this.fields.has(Tag.Mint)) {
|
|
519
|
-
+ return (0, fts_1.none)();
|
|
520
|
-
+ }
|
|
521
|
-
+ const [block, tx] = this.fields.get(Tag.Mint);
|
|
522
|
-
+ return (0, fts_1.some)(new RuneId(Number(block), Number(tx)));
|
|
523
|
-
+ }
|
|
524
|
-
+ getEtching() {
|
|
525
|
-
+ if (!this.hasFlags(Flag.Etching)) {
|
|
526
|
-
+ return (0, fts_1.none)();
|
|
527
|
-
+ }
|
|
528
|
-
+ const divisibility = this.getDivisibility();
|
|
529
|
-
+ const premine = this.getPremine();
|
|
530
|
-
+ const rune = this.getRune();
|
|
531
|
-
+ const spacers = this.getSpacers();
|
|
532
|
-
+ const symbol = this.getSymbol();
|
|
533
|
-
+ const terms = this.getTerms();
|
|
534
|
-
+ const turbo = this.hasFlags(Flag.Turbo);
|
|
535
|
-
+ return (0, fts_1.some)(new Etching(divisibility, premine, rune, spacers, symbol, terms, turbo));
|
|
536
|
-
+ }
|
|
537
|
-
+ getDivisibility() {
|
|
538
|
-
+ if (!this.fields.has(Tag.Divisibility)) {
|
|
539
|
-
+ return (0, fts_1.none)();
|
|
540
|
-
+ }
|
|
541
|
-
+ const [divisibility] = this.fields.get(Tag.Divisibility);
|
|
542
|
-
+ if (divisibility > Etching.MAX_DIVISIBILITY) {
|
|
543
|
-
+ throw new Error("invalid divisibility");
|
|
544
|
-
+ }
|
|
545
|
-
+ return (0, fts_1.some)(Number(divisibility));
|
|
546
|
-
+ }
|
|
547
|
-
+ getPremine() {
|
|
548
|
-
+ if (!this.fields.has(Tag.Premine)) {
|
|
549
|
-
+ return (0, fts_1.none)();
|
|
550
|
-
+ }
|
|
551
|
-
+ const [premine] = this.fields.get(Tag.Premine);
|
|
552
|
-
+ return (0, fts_1.some)(Number(premine));
|
|
553
|
-
+ }
|
|
554
|
-
+ getRune() {
|
|
555
|
-
+ if (!this.fields.has(Tag.Rune)) {
|
|
556
|
-
+ return (0, fts_1.none)();
|
|
557
|
-
+ }
|
|
558
|
-
+ const [rune] = this.fields.get(Tag.Rune);
|
|
559
|
-
+ return (0, fts_1.some)(new Rune(rune));
|
|
560
|
-
+ }
|
|
561
|
-
+ getSpacers() {
|
|
562
|
-
+ if (!this.fields.has(Tag.Spacers)) {
|
|
563
|
-
+ return (0, fts_1.none)();
|
|
564
|
-
+ }
|
|
565
|
-
+ const [spacers] = this.fields.get(Tag.Spacers);
|
|
566
|
-
+ if (spacers > Etching.MAX_SPACERS) {
|
|
567
|
-
+ throw new Error("invalid spacers");
|
|
568
|
-
+ }
|
|
569
|
-
+ return (0, fts_1.some)(Number(spacers));
|
|
570
|
-
+ }
|
|
571
|
-
+ getHeightStart() {
|
|
572
|
-
+ if (!this.fields.has(Tag.HeightStart)) {
|
|
573
|
-
+ return (0, fts_1.none)();
|
|
574
|
-
+ }
|
|
575
|
-
+ const [heightStart] = this.fields.get(Tag.HeightStart);
|
|
576
|
-
+ return (0, fts_1.some)(Number(heightStart));
|
|
577
|
-
+ }
|
|
578
|
-
+ getHeightEnd() {
|
|
579
|
-
+ if (!this.fields.has(Tag.HeightEnd)) {
|
|
580
|
-
+ return (0, fts_1.none)();
|
|
581
|
-
+ }
|
|
582
|
-
+ const [heightEnd] = this.fields.get(Tag.HeightEnd);
|
|
583
|
-
+ return (0, fts_1.some)(Number(heightEnd));
|
|
584
|
-
+ }
|
|
585
|
-
+ getOffsetStart() {
|
|
586
|
-
+ if (!this.fields.has(Tag.OffsetStart)) {
|
|
587
|
-
+ return (0, fts_1.none)();
|
|
588
|
-
+ }
|
|
589
|
-
+ const [offsetStart] = this.fields.get(Tag.OffsetStart);
|
|
590
|
-
+ return (0, fts_1.some)(Number(offsetStart));
|
|
591
|
-
+ }
|
|
592
|
-
+ getOffsetEnd() {
|
|
593
|
-
+ if (!this.fields.has(Tag.OffsetEnd)) {
|
|
594
|
-
+ return (0, fts_1.none)();
|
|
595
|
-
+ }
|
|
596
|
-
+ const [offsetEnd] = this.fields.get(Tag.OffsetEnd);
|
|
597
|
-
+ return (0, fts_1.some)(Number(offsetEnd));
|
|
598
|
-
+ }
|
|
599
|
-
+ getCap() {
|
|
600
|
-
+ if (!this.fields.has(Tag.Cap)) {
|
|
601
|
-
+ return (0, fts_1.none)();
|
|
602
|
-
+ }
|
|
603
|
-
+ const [cap] = this.fields.get(Tag.Cap);
|
|
604
|
-
+ return (0, fts_1.some)(Number(cap));
|
|
605
|
-
+ }
|
|
606
|
-
+ getAmount() {
|
|
607
|
-
+ if (!this.fields.has(Tag.Amount)) {
|
|
608
|
-
+ return (0, fts_1.none)();
|
|
609
|
-
+ }
|
|
610
|
-
+ const [amount] = this.fields.get(Tag.Amount);
|
|
611
|
-
+ return (0, fts_1.some)(Number(amount));
|
|
612
|
-
+ }
|
|
613
|
-
+ getSymbol() {
|
|
614
|
-
+ if (!this.fields.has(Tag.Symbol)) {
|
|
615
|
-
+ return (0, fts_1.none)();
|
|
616
|
-
+ }
|
|
617
|
-
+ const [symbol] = this.fields.get(Tag.Symbol);
|
|
618
|
-
+ return (0, fts_1.some)(String.fromCharCode(Number(symbol)));
|
|
619
|
-
+ }
|
|
620
|
-
+ getTerms() {
|
|
621
|
-
+ if (!this.hasFlags(Flag.Terms)) {
|
|
622
|
-
+ return (0, fts_1.none)();
|
|
623
|
-
+ }
|
|
624
|
-
+ const cap = this.getCap();
|
|
625
|
-
+ if (!cap.isSome()) {
|
|
626
|
-
+ throw new Error("no cap field");
|
|
627
|
-
+ }
|
|
628
|
-
+ const amount = this.getAmount();
|
|
629
|
-
+ if (!amount.isSome()) {
|
|
630
|
-
+ throw new Error("no amount field");
|
|
631
|
-
+ }
|
|
632
|
-
+ const heightStart = this.getHeightStart();
|
|
633
|
-
+ const heightEnd = this.getHeightEnd();
|
|
634
|
-
+ const offsetStart = this.getOffsetStart();
|
|
635
|
-
+ const offsetEnd = this.getOffsetEnd();
|
|
636
|
-
+ const height = new Range(heightStart, heightEnd);
|
|
637
|
-
+ const offset = new Range(offsetStart, offsetEnd);
|
|
638
|
-
+ return (0, fts_1.some)(new Terms(amount.value(), cap.value(), height, offset));
|
|
639
|
-
+ }
|
|
640
|
-
+ getPointer() {
|
|
641
|
-
+ if (!this.fields.has(Tag.Pointer)) {
|
|
642
|
-
+ return (0, fts_1.none)();
|
|
643
|
-
+ }
|
|
644
|
-
+ const [pointer] = this.fields.get(Tag.Pointer);
|
|
645
|
-
+ return (0, fts_1.some)(Number(pointer));
|
|
646
|
-
+ }
|
|
647
|
-
+}
|
|
648
|
-
+exports.Message = Message;
|
|
649
|
-
+class EtchInscription {
|
|
650
|
-
+ constructor(fields = new Map(), data = Buffer.alloc(0)) {
|
|
651
|
-
+ this.fields = fields;
|
|
652
|
-
+ this.data = data;
|
|
653
|
-
+ }
|
|
654
|
-
+ setContent(contentType, data) {
|
|
655
|
-
+ this.fields.set(1, Buffer.from(contentType, 'utf8'));
|
|
656
|
-
+ this.data = data;
|
|
657
|
-
+ }
|
|
658
|
-
+ setRune(rune) {
|
|
659
|
-
+ const n = (0, base26_1.base26Encode)((0, spacers_1.removeSpacers)(rune));
|
|
660
|
-
+ let nstr = n.toString(16);
|
|
661
|
-
+ if (nstr.length % 2 === 1) {
|
|
662
|
-
+ nstr = '0' + nstr;
|
|
663
|
-
+ }
|
|
664
|
-
+ this.setField(EtchInscription.Tag.RUNE, Buffer.from(nstr, 'hex').reverse());
|
|
665
|
-
+ }
|
|
666
|
-
+ setField(field, val) {
|
|
667
|
-
+ this.fields.set(field, val);
|
|
668
|
-
+ }
|
|
669
|
-
+ static decipher(rawTx, inputIdx) {
|
|
670
|
-
+ const tx = bitcoinjs_lib_1.Transaction.fromHex(rawTx);
|
|
671
|
-
+ const witness = tx.ins[inputIdx].witness;
|
|
672
|
-
+ const tapscript = witness[1];
|
|
673
|
-
+ const ls = bitcoinjs_lib_1.script.decompile(tapscript);
|
|
674
|
-
+ const fields = new Map();
|
|
675
|
-
+ const dataChunks = [];
|
|
676
|
-
+ let isData = false;
|
|
677
|
-
+ for (let i = 5; i < ls.length - 1;) {
|
|
678
|
-
+ const chunk = ls[i];
|
|
679
|
-
+ if (chunk === 0) {
|
|
680
|
-
+ isData = true;
|
|
681
|
-
+ i++;
|
|
682
|
-
+ continue;
|
|
683
|
-
+ }
|
|
684
|
-
+ else if (isData) {
|
|
685
|
-
+ // Data
|
|
686
|
-
+ dataChunks.push(chunk);
|
|
687
|
-
+ i++;
|
|
688
|
-
+ }
|
|
689
|
-
+ else {
|
|
690
|
-
+ // Fields
|
|
691
|
-
+ const tag = chunk - 80;
|
|
692
|
-
+ const val = ls[i + 1];
|
|
693
|
-
+ if (typeof val == 'number') {
|
|
694
|
-
+ const buff = Buffer.alloc(1);
|
|
695
|
-
+ buff.writeUInt8(val);
|
|
696
|
-
+ fields.set(tag, buff);
|
|
697
|
-
+ }
|
|
698
|
-
+ else {
|
|
699
|
-
+ fields.set(tag, val);
|
|
700
|
-
+ }
|
|
701
|
-
+ i += 2;
|
|
702
|
-
+ }
|
|
703
|
-
+ }
|
|
704
|
-
+ return new EtchInscription(fields, Buffer.concat(dataChunks));
|
|
705
|
-
+ }
|
|
706
|
-
+ encipher() {
|
|
707
|
-
+ const res = [];
|
|
708
|
-
+ if (this.data && this.data.length > 0) {
|
|
709
|
-
+ res.push(Buffer.from('0063036f7264', 'hex') // 0 OP_IF "ord"
|
|
710
|
-
+ );
|
|
711
|
-
+ Array.from(this.fields.entries())
|
|
712
|
-
+ .sort((a, b) => a[0] - b[0]) // Sorting by tag in ascending order
|
|
713
|
-
+ .forEach(([tag, val]) => {
|
|
714
|
-
+ const tagBuff = Buffer.alloc(1);
|
|
715
|
-
+ tagBuff.writeUInt8(tag);
|
|
716
|
-
+ res.push(Buffer.from('01', 'hex'));
|
|
717
|
-
+ res.push(tagBuff);
|
|
718
|
-
+ if (val.length != 1 || val[0] != 0x00) {
|
|
719
|
-
+ res.push((0, utils_1.toPushData)(val));
|
|
720
|
-
+ }
|
|
721
|
-
+ else {
|
|
722
|
-
+ res.push(val);
|
|
723
|
-
+ }
|
|
724
|
-
+ });
|
|
725
|
-
+ res.push(Buffer.from('00', 'hex'));
|
|
726
|
-
+ const dataChunks = (0, utils_1.chunks)(Array.from(this.data), 520);
|
|
727
|
-
+ for (const chunk of dataChunks) {
|
|
728
|
-
+ res.push((0, utils_1.toPushData)(Buffer.from(chunk)));
|
|
729
|
-
+ }
|
|
730
|
-
+ }
|
|
731
|
-
+ else {
|
|
732
|
-
+ res.push(Buffer.from('0063', 'hex') // 0 OP_IF
|
|
733
|
-
+ );
|
|
734
|
-
+ const rune = this.fields.get(EtchInscription.Tag.RUNE);
|
|
735
|
-
+ if (!rune) {
|
|
736
|
-
+ throw new Error(`No rune found!`);
|
|
737
|
-
+ }
|
|
738
|
-
+ res.push((0, utils_1.toPushData)(rune));
|
|
739
|
-
+ }
|
|
740
|
-
+ res.push(Buffer.from('68', 'hex')); // OP_ENDIF
|
|
741
|
-
+ return Buffer.concat(res);
|
|
742
|
-
+ }
|
|
743
|
-
+}
|
|
744
|
-
+exports.EtchInscription = EtchInscription;
|
|
745
|
-
+EtchInscription.Tag = {
|
|
746
|
-
+ CONTENT_TYPE: 1,
|
|
747
|
-
+ POINTER: 2,
|
|
748
|
-
+ PARENT: 3,
|
|
749
|
-
+ METADATA: 5,
|
|
750
|
-
+ METAPROTOCOL: 7,
|
|
751
|
-
+ CONTENT_ENCODING: 9,
|
|
752
|
-
+ DELEGATE: 11,
|
|
753
|
-
+ RUNE: 13
|
|
754
|
-
+};
|
|
755
|
-
diff --git a/node_modules/runelib/dist/utils.js b/node_modules/runelib/dist/utils.js
|
|
756
|
-
index 4d70a9e..1ff1e1e 100644
|
|
757
|
-
--- a/node_modules/runelib/dist/utils.js
|
|
758
|
-
+++ b/node_modules/runelib/dist/utils.js
|
|
759
|
-
@@ -60,14 +60,14 @@ function toPushData(data) {
|
|
760
|
-
// OP_PUSHDATA2
|
|
761
|
-
res.push(Buffer.from('4d', 'hex'));
|
|
762
|
-
const dLenBuff = Buffer.alloc(2);
|
|
763
|
-
- dLenBuff.writeUint16LE(dLen);
|
|
764
|
-
+ dLenBuff.writeUInt16LE(dLen);
|
|
765
|
-
res.push(dLenBuff);
|
|
766
|
-
}
|
|
767
|
-
else {
|
|
768
|
-
// OP_PUSHDATA4
|
|
769
|
-
res.push(Buffer.from('4e', 'hex'));
|
|
770
|
-
const dLenBuff = Buffer.alloc(4);
|
|
771
|
-
- dLenBuff.writeUint32LE(dLen);
|
|
772
|
-
+ dLenBuff.writeUInt32LE(dLen);
|
|
773
|
-
res.push(dLenBuff);
|
|
774
|
-
}
|
|
775
|
-
res.push(data);
|
|
776
|
-
diff --git a/node_modules/runelib/dist/utils.js.bak b/node_modules/runelib/dist/utils.js.bak
|
|
777
|
-
new file mode 100644
|
|
778
|
-
index 0000000..fad0b84
|
|
779
|
-
--- /dev/null
|
|
780
|
-
+++ b/node_modules/runelib/dist/utils.js.bak
|
|
781
|
-
@@ -0,0 +1,76 @@
|
|
782
|
-
+"use strict";
|
|
783
|
-
+Object.defineProperty(exports, "__esModule", { value: true });
|
|
784
|
-
+exports.toPushData = exports.chunks = exports.toHex = exports.zero2 = void 0;
|
|
785
|
-
+/**
|
|
786
|
-
+ * Prepends a '0' to an odd character length word to ensure it has an even number of characters.
|
|
787
|
-
+ * @param {string} word - The input word.
|
|
788
|
-
+ * @returns {string} - The word with a leading '0' if it's an odd character length; otherwise, the original word.
|
|
789
|
-
+ */
|
|
790
|
-
+const zero2 = (word) => {
|
|
791
|
-
+ if (word.length % 2 === 1) {
|
|
792
|
-
+ return '0' + word;
|
|
793
|
-
+ }
|
|
794
|
-
+ else {
|
|
795
|
-
+ return word;
|
|
796
|
-
+ }
|
|
797
|
-
+};
|
|
798
|
-
+exports.zero2 = zero2;
|
|
799
|
-
+/**
|
|
800
|
-
+ * Converts an array of numbers to a hexadecimal string representation.
|
|
801
|
-
+ * @param {number[]} msg - The input array of numbers.
|
|
802
|
-
+ * @returns {string} - The hexadecimal string representation of the input array.
|
|
803
|
-
+ */
|
|
804
|
-
+const toHex = (msg) => {
|
|
805
|
-
+ let res = '';
|
|
806
|
-
+ for (let i = 0; i < msg.length; i++) {
|
|
807
|
-
+ res += (0, exports.zero2)(msg[i].toString(16));
|
|
808
|
-
+ }
|
|
809
|
-
+ return res;
|
|
810
|
-
+};
|
|
811
|
-
+exports.toHex = toHex;
|
|
812
|
-
+function chunks(bin, chunkSize) {
|
|
813
|
-
+ const chunks = [];
|
|
814
|
-
+ let offset = 0;
|
|
815
|
-
+ while (offset < bin.length) {
|
|
816
|
-
+ // Use Buffer.slice to create a chunk. This method does not copy the memory;
|
|
817
|
-
+ // it creates a new Buffer that references the original memory.
|
|
818
|
-
+ const chunk = bin.slice(offset, offset + chunkSize);
|
|
819
|
-
+ chunks.push(chunk);
|
|
820
|
-
+ offset += chunkSize;
|
|
821
|
-
+ }
|
|
822
|
-
+ return chunks;
|
|
823
|
-
+}
|
|
824
|
-
+exports.chunks = chunks;
|
|
825
|
-
+function toPushData(data) {
|
|
826
|
-
+ const res = [];
|
|
827
|
-
+ const dLen = data.length;
|
|
828
|
-
+ if (dLen < 0x4c) {
|
|
829
|
-
+ const dLenBuff = Buffer.alloc(1);
|
|
830
|
-
+ dLenBuff.writeUInt8(dLen);
|
|
831
|
-
+ res.push(dLenBuff);
|
|
832
|
-
+ }
|
|
833
|
-
+ else if (dLen <= 0xff) {
|
|
834
|
-
+ // OP_PUSHDATA1
|
|
835
|
-
+ res.push(Buffer.from('4c', 'hex'));
|
|
836
|
-
+ const dLenBuff = Buffer.alloc(1);
|
|
837
|
-
+ dLenBuff.writeUInt8(dLen);
|
|
838
|
-
+ res.push(dLenBuff);
|
|
839
|
-
+ }
|
|
840
|
-
+ else if (dLen <= 0xffff) {
|
|
841
|
-
+ // OP_PUSHDATA2
|
|
842
|
-
+ res.push(Buffer.from('4d', 'hex'));
|
|
843
|
-
+ const dLenBuff = Buffer.alloc(2);
|
|
844
|
-
+ dLenBuff.writeUInt16LE(dLen);
|
|
845
|
-
+ res.push(dLenBuff);
|
|
846
|
-
+ }
|
|
847
|
-
+ else {
|
|
848
|
-
+ // OP_PUSHDATA4
|
|
849
|
-
+ res.push(Buffer.from('4e', 'hex'));
|
|
850
|
-
+ const dLenBuff = Buffer.alloc(4);
|
|
851
|
-
+ dLenBuff.writeUint32LE(dLen);
|
|
852
|
-
+ res.push(dLenBuff);
|
|
853
|
-
+ }
|
|
854
|
-
+ res.push(data);
|
|
855
|
-
+ return Buffer.concat(res);
|
|
856
|
-
+}
|
|
857
|
-
+exports.toPushData = toPushData;
|