From fe771fa9463944205b4be9e9b649347d2deac33e Mon Sep 17 00:00:00 2001 From: "Tristan (t4t5)" Date: Sun, 22 Dec 2024 09:30:35 +0100 Subject: [PATCH 1/2] Monkey-patch pointer=0 --- src/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index ed1fb7f..cc1f521 100644 --- a/src/index.ts +++ b/src/index.ts @@ -113,7 +113,13 @@ const TagCoder: P.Coder = { for (const p of to.parent) res.push({ tag: tagName, data: TagCoders.parent.encode(p) }); continue; } - const bytes = TagCoders[field as TagName].encode(to[field as TagName]); + let bytes = TagCoders[field as TagName].encode(to[field as TagName]); + + // Handle pointer = 0: + if (field === 'pointer' && bytes.length === 0) { + bytes = new Uint8Array([0]); + } + for (const data of splitChunks(bytes)) res.push({ tag: tagName, data }); } if (to.unknown) { From b8f9391089fa8c83e2f7651ccbaa024d9d1ffd55 Mon Sep 17 00:00:00 2001 From: "Tristan (t4t5)" Date: Sun, 22 Dec 2024 09:59:17 +0100 Subject: [PATCH 2/2] Add test for pointer = 0 --- test/ordinals.test.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/ordinals.test.js b/test/ordinals.test.js index 47fd001..15fc340 100644 --- a/test/ordinals.test.js +++ b/test/ordinals.test.js @@ -1,4 +1,4 @@ -import { deepStrictEqual } from 'node:assert'; +import { deepStrictEqual, strictEqual } from 'node:assert'; import { describe, should } from 'micro-should'; import { hex, utf8 } from '@scure/base'; import * as btc from '@scure/btc-signer'; @@ -67,6 +67,17 @@ describe('Ordinals', () => { }); }); + should('support explicit pointer 0', () => { + const { TagCoder } = ordinals.__test__; + const encoded = TagCoder.decode({ pointer: 0n }); + + const encodedTag = encoded[0].tag[0] + const encodedValue = encoded[0].data[0] + + strictEqual(encodedTag, 2); + strictEqual(encodedValue, 0); + }) + should('inscription/11820782', () => { // https://ordiscan.com/inscription/11820782 const rawTx = ordvectors[0].raw_tx;