mainnet-js 1.1.22 → 1.1.23

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/index.html CHANGED
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <meta charset="utf-8">
5
5
  <title>The Empty Mainnet App</title>
6
- <meta name="viewport" content="width=device-width, initial-scale=1"><script defer src="mainnet-1.1.22.js"></script></head>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1"><script defer src="mainnet-1.1.23.js"></script></head>
7
7
  <body><script>document.addEventListener("DOMContentLoaded", async (event) => Object.assign(globalThis, await __mainnetPromise))</script>
8
8
  </body>
9
9
  </html>
@@ -1634,7 +1634,7 @@ eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__
1634
1634
  \****************************/
1635
1635
  /***/ ((module, __webpack_exports__, __webpack_require__) => {
1636
1636
 
1637
- eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"BCMR\": () => (/* binding */ BCMR)\n/* harmony export */ });\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @bitauth/libauth */ \"../../node_modules/@bitauth/libauth/build/lib/format/hex.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @bitauth/libauth */ \"../../node_modules/@bitauth/libauth/build/lib/crypto/default-crypto-instances.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @bitauth/libauth */ \"../../node_modules/@bitauth/libauth/build/lib/format/utf8.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! @bitauth/libauth */ \"../../node_modules/@bitauth/libauth/build/lib/message/transaction-encoding.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! axios */ \"../../node_modules/axios/index.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(axios__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _interface_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../interface.js */ \"./src/interface.ts\");\n/* harmony import */ var _network_Connection_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../network/Connection.js */ \"./src/network/Connection.ts\");\n/* harmony import */ var _model_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./model.js */ \"./src/wallet/model.ts\");\nvar __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__, _network_Connection_js__WEBPACK_IMPORTED_MODULE_5__, _model_js__WEBPACK_IMPORTED_MODULE_6__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_7__]);\n([_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__, _network_Connection_js__WEBPACK_IMPORTED_MODULE_5__, _model_js__WEBPACK_IMPORTED_MODULE_6__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_7__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);\n\n\n\n\n\n// Implementation of CHIP-BCMR v1.0.0, refer to https://github.com/bitjson/chip-bcmr\nclass BCMR {\n static getRegistries() {\n return this.metadataRegistries;\n }\n static resetRegistries() {\n this.metadataRegistries = [];\n }\n /**\n * fetchMetadataRegistry Fetch the BCMR registry JSON file from a remote URI, optionally verifying its content hash\n *\n * @param {string} uri URI of the registry to fetch from\n * @param {string?} contentHash SHA256 hash of the resource the `uri` parameter points at.\n * If specified, calculates the hash of the data fetched from `uri` and matches it with provided one.\n * Yields an error upon mismatch.\n *\n * @returns {Registry} resolved registry\n */\n static async fetchMetadataRegistry(uri, contentHash) {\n if (uri.indexOf(\"https://\") < 0) {\n uri = `https://${uri}`;\n }\n // content hashes HTTPS Publication Outputs per spec\n if (contentHash) {\n // request as text and verify hash\n const response = await axios__WEBPACK_IMPORTED_MODULE_0___default().get(uri, {\n responseType: \"text\",\n transformResponse: (val) => {\n return val;\n },\n });\n const hash = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.sha256.hash((0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__.utf8ToBin)(response.data)));\n if (contentHash != hash) {\n throw new Error(`Content hash mismatch for URI: ${uri}\\nreceived: ${hash}\\nrequired: ${contentHash}`);\n }\n return JSON.parse(response.data);\n }\n // request as JSON\n const response = await axios__WEBPACK_IMPORTED_MODULE_0___default().get(uri);\n return response.data;\n }\n /**\n * addMetadataRegistry Add the metadata registry to the list of tracked registries\n *\n * @param {Registry} registry Registry object per schema specification, see https://raw.githubusercontent.com/bitjson/chip-bcmr/master/bcmr-v1.schema.json\n *\n */\n static addMetadataRegistry(registry) {\n if (this.metadataRegistries.some((val) => JSON.stringify(val) === JSON.stringify(registry))) {\n return;\n }\n this.metadataRegistries.push(registry);\n }\n /**\n * addMetadataRegistryFromUri Add the metadata registry by fetching a JSON file from a remote URI, optionally verifying its content hash\n *\n * @param {string} uri URI of the registry to fetch from\n * @param {string?} contentHash SHA256 hash of the resource the `uri` parameter points at.\n * If specified, calculates the hash of the data fetched from `uri` and matches it with provided one.\n * Yields an error upon mismatch.\n *\n */\n static async addMetadataRegistryFromUri(uri, contentHash) {\n const registry = await this.fetchMetadataRegistry(uri, contentHash);\n this.addMetadataRegistry(registry);\n }\n /**\n * buildAuthChain Build an authchain - Zeroth-Descendant Transaction Chain, refer to https://github.com/bitjson/chip-bcmr#zeroth-descendant-transaction-chains\n * The authchain in this implementation is specific to resolve to a valid metadata registry\n *\n * @param {string} options.transactionHash (required) transaction hash from which to build the auth chain\n * @param {Network?} options.network (default=mainnet) network to query the data from\n * @param {boolean?} options.resolveBase (default=false) boolean flag to indicate that autchain building should resolve and verify elements back to base or be stopped at this exact chain element\n * @param {boolean?} options.followToHead (default=true) boolean flag to indicate that autchain building should progress to head or be stopped at this exact chain element\n * @param {ElectrumRawTransaction?} options.rawTx cached raw transaction obtained previously, spares a Fulcrum call\n * @param {TxI[]?} options.historyCache cached address history to be reused if authchain building proceeds with the same address, spares a flurry of Fulcrum calls\n *\n * @returns {AuthChain} returns the resolved authchain\n */\n static async buildAuthChain(options) {\n if (options.network === undefined) {\n options.network = _interface_js__WEBPACK_IMPORTED_MODULE_4__.Network.MAINNET;\n }\n if (options.followToHead === undefined) {\n options.followToHead = true;\n }\n if (options.resolveBase === undefined) {\n options.resolveBase = false;\n }\n const provider = (await (0,_network_Connection_js__WEBPACK_IMPORTED_MODULE_5__.initProvider)(options.network));\n if (options.rawTx === undefined) {\n options.rawTx = await provider.getRawTransactionObject(options.transactionHash);\n }\n // figure out the autchain by moving towards authhead\n const getAuthChainChild = async () => {\n const history = options.historyCache ||\n (await provider.getHistory(options.rawTx.vout[0].scriptPubKey.addresses[0]));\n const thisTx = history.find((val) => val.tx_hash === options.transactionHash);\n let filteredHistory = history.filter((val) => val.height > 0\n ? val.height >= thisTx.height || val.height <= 0\n : val.height <= 0 && val.tx_hash !== thisTx.tx_hash);\n for (const historyTx of filteredHistory) {\n const historyRawTx = await provider.getRawTransactionObject(historyTx.tx_hash);\n const authChainVin = historyRawTx.vin.find((val) => val.txid === options.transactionHash && val.vout === 0);\n // if we've found continuation of authchain, we shall recurse into it\n if (authChainVin) {\n // reuse queried address history if the next element in chain is the same address\n const historyCache = options.rawTx.vout[0].scriptPubKey.addresses[0] ===\n historyRawTx.vout[0].scriptPubKey.addresses[0]\n ? filteredHistory\n : undefined;\n // combine the authchain element with the rest obtained\n return { rawTx: historyRawTx, historyCache };\n }\n }\n return undefined;\n };\n // helper function to enforce the constraints on the 0th output, decode the BCMR's OP_RETURN data\n // returns resolved AuthChainElement\n const makeAuthChainElement = (rawTx, hash) => {\n let opReturns;\n let spends0thOutput = false;\n if (rawTx.hasOwnProperty(\"vout\")) {\n const electrumTransaction = rawTx;\n opReturns = electrumTransaction.vout\n .filter((val) => val.scriptPubKey.type === \"nulldata\")\n .map((val) => val.scriptPubKey.hex);\n spends0thOutput = electrumTransaction.vin.some((val) => val.vout === 0);\n }\n else {\n const libauthTransaction = rawTx;\n opReturns = libauthTransaction.outputs\n .map((val) => (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(val.lockingBytecode))\n .filter((val) => val.indexOf(\"6a\") === 0);\n spends0thOutput = libauthTransaction.inputs.some((val) => val.outpointIndex === 0);\n }\n if (!spends0thOutput) {\n throw new Error(\"Invalid authchain transaction (does not spend 0th output of previous transaction)\");\n }\n const bcmrOpReturns = opReturns.filter((val) => val.indexOf(\"6a0442434d52\") === 0 ||\n val.indexOf(\"6a4c0442434d52\") === 0 ||\n val.indexOf(\"6a4d040042434d52\") === 0 ||\n val.indexOf(\"6a4e0400000042434d52\") === 0);\n if (bcmrOpReturns.length === 0) {\n return {\n txHash: hash,\n contentHash: \"\",\n uris: [],\n httpsUrl: \"\",\n };\n }\n const opReturnHex = opReturns[0];\n const chunks = _model_js__WEBPACK_IMPORTED_MODULE_6__.OpReturnData.parseBinary((0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.hexToBin)(opReturnHex));\n if (chunks.length < 2) {\n throw new Error(`Malformed BCMR output: ${opReturnHex}`);\n }\n const result = {\n txHash: hash,\n contentHash: \"\",\n uris: [],\n httpsUrl: \"\",\n };\n if (chunks.length === 2) {\n // IPFS Publication Output\n result.contentHash = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(chunks[1]);\n const ipfsCid = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__.binToUtf8)(chunks[1]);\n result.uris = [`ipfs://${ipfsCid}`];\n result.httpsUrl = `https://dweb.link/ipfs/${ipfsCid}`;\n }\n else {\n // URI Publication Output\n // content hash is in OP_SHA256 byte order per spec\n result.contentHash = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(chunks[1].slice());\n const uris = chunks.slice(2);\n for (const uri of uris) {\n const uriString = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__.binToUtf8)(uri);\n result.uris.push(uriString);\n if (result.httpsUrl) {\n continue;\n }\n if (uriString.indexOf(\"https://\") === 0) {\n result.httpsUrl = uriString;\n }\n else if (uriString.indexOf(\"https://\") === -1) {\n result.httpsUrl = uriString;\n // case for domain name specifier, like example.com\n if (uriString.indexOf(\"/\") === -1) {\n result.httpsUrl = `${result.httpsUrl}/.well-known/bitcoin-cash-metadata-registry.json`;\n }\n result.httpsUrl = `https://${result.httpsUrl}`;\n }\n else if (uriString.indexOf(\"ipfs://\") === 0) {\n const ipfsCid = uriString.replace(\"ipfs://\", \"\");\n result.httpsUrl = `https://dweb.link/ipfs/${ipfsCid}`;\n }\n else {\n throw new Error(`Unsupported uri type: ${uriString}`);\n }\n }\n }\n return result;\n };\n // make authchain element and combine with the rest obtained\n let element;\n try {\n element = makeAuthChainElement(options.rawTx, options.rawTx.hash);\n }\n catch (error) {\n // special case for cashtoken authchain lookup by categoryId - allow to fail first lookup and inspect the genesis transaction\n // follow authchain to head and look for BCMR outputs\n const child = await getAuthChainChild();\n if (child) {\n return await BCMR.buildAuthChain({\n ...options,\n transactionHash: child.rawTx.hash,\n rawTx: child.rawTx,\n historyCache: child.historyCache,\n });\n }\n else {\n throw error;\n }\n }\n let chainBase = [];\n if (options.resolveBase) {\n // check for accelerated path if \"authchain\" extension is in registry\n const registry = await this.fetchMetadataRegistry(element.httpsUrl, element.contentHash);\n if (registry.extensions &&\n registry.extensions[\"authchain\"] &&\n Object.keys(registry.extensions[\"authchain\"]).length) {\n const chainTxArray = Object.values(registry.extensions[\"authchain\"]);\n chainBase = chainTxArray\n .map((tx) => {\n const transactionBin = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.hexToBin)(tx);\n const decoded = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_7__.decodeTransaction)(transactionBin);\n if (typeof decoded === \"string\") {\n throw new Error(`Error decoding transaction ${JSON.stringify(tx)}, ${decoded}`);\n }\n const hash = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.sha256.hash(_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.sha256.hash(transactionBin)).reverse());\n return { decoded, hash };\n })\n .map(({ decoded, hash }) => makeAuthChainElement(decoded, hash));\n }\n else {\n // simply go back in history towards authhead\n let stop = false;\n let tx = { ...options.rawTx };\n let maxElements = 10;\n while (stop == false || maxElements === 0) {\n const vin = tx.vin.find((val) => val.vout === 0);\n tx = await provider.getRawTransactionObject(vin.txid);\n try {\n const pastElement = makeAuthChainElement(tx, tx.hash);\n chainBase.unshift(pastElement);\n maxElements--;\n }\n catch {\n stop = true;\n }\n }\n }\n }\n // if we follow to head, we need to locate the next transaction spending our 0th output\n // and repeat the building process recursively\n if (options.followToHead) {\n const child = await getAuthChainChild();\n if (child) {\n const chainHead = await BCMR.buildAuthChain({\n transactionHash: child.rawTx.hash,\n network: options.network,\n rawTx: child.rawTx,\n historyCache: child.historyCache,\n followToHead: options.followToHead,\n resolveBase: false,\n });\n // combine the authchain element with the rest obtained\n return [...chainBase, element, ...chainHead].filter((val) => val.httpsUrl.length);\n }\n }\n // return the last chain element (or the only found in an edge case)\n return [...chainBase, element].filter((val) => val.httpsUrl.length);\n }\n /**\n * addMetadataRegistryAuthChain Add BCMR metadata registry by resolving an authchain\n *\n * @param {string} options.transactionHash (required) transaction hash from which to build the auth chain\n * @param {Network?} options.network (default=mainnet) network to query the data from\n * @param {boolean?} options.followToHead (default=true) boolean flag to indicate that autchain building should progress to head (most recent registry version) or be stopped at this exact chain element\n * @param {ElectrumRawTransaction?} options.rawTx cached raw transaction obtained previously, spares a Fulcrum call\n *\n * @returns {AuthChain} returns the resolved authchain\n */\n static async addMetadataRegistryAuthChain(options) {\n const authChain = await this.buildAuthChain({\n ...options,\n resolveBase: false,\n });\n if (!authChain.length) {\n throw new Error(`There were no BCMR entries in the resolved authchain ${JSON.stringify(authChain, null, 2)}`);\n }\n const registry = await this.fetchMetadataRegistry(authChain.reverse()[0].httpsUrl);\n this.addMetadataRegistry(registry);\n return authChain;\n }\n /**\n * getTokenInfo Return the token info (or the identity snapshot as per spec)\n *\n * @param {string} tokenId token id to look up\n *\n * @returns {IdentitySnapshot?} return the info for the token found, otherwise undefined\n */\n static getTokenInfo(tokenId) {\n for (const registry of this.metadataRegistries.slice().reverse()) {\n const history = registry.identities?.[tokenId];\n if (!history) {\n continue;\n }\n const latestIdentityIndex = Object.keys(history)[0];\n if (latestIdentityIndex === undefined) {\n continue;\n }\n return history[latestIdentityIndex];\n }\n return undefined;\n }\n}\n// List of tracked registries\nBCMR.metadataRegistries = [];\n\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } });\n\n//# sourceURL=webpack://mainnet-js/./src/wallet/Bcmr.ts?");
1637
+ eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"BCMR\": () => (/* binding */ BCMR)\n/* harmony export */ });\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @bitauth/libauth */ \"../../node_modules/@bitauth/libauth/build/lib/format/hex.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @bitauth/libauth */ \"../../node_modules/@bitauth/libauth/build/lib/crypto/default-crypto-instances.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @bitauth/libauth */ \"../../node_modules/@bitauth/libauth/build/lib/format/utf8.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! @bitauth/libauth */ \"../../node_modules/@bitauth/libauth/build/lib/message/transaction-encoding.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! axios */ \"../../node_modules/axios/index.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(axios__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _interface_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../interface.js */ \"./src/interface.ts\");\n/* harmony import */ var _network_Connection_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../network/Connection.js */ \"./src/network/Connection.ts\");\n/* harmony import */ var _model_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./model.js */ \"./src/wallet/model.ts\");\nvar __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__, _model_js__WEBPACK_IMPORTED_MODULE_4__, _network_Connection_js__WEBPACK_IMPORTED_MODULE_6__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_7__]);\n([_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__, _model_js__WEBPACK_IMPORTED_MODULE_4__, _network_Connection_js__WEBPACK_IMPORTED_MODULE_6__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_7__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);\n\n\n\n\n\n// Implementation of CHIP-BCMR v2.0.0-draft, refer to https://github.com/bitjson/chip-bcmr\nclass BCMR {\n static getRegistries() {\n return this.metadataRegistries;\n }\n static resetRegistries() {\n this.metadataRegistries = [];\n }\n /**\n * fetchMetadataRegistry Fetch the BCMR registry JSON file from a remote URI, optionally verifying its content hash\n *\n * @param {string} uri URI of the registry to fetch from\n * @param {string?} contentHash SHA256 hash of the resource the `uri` parameter points at.\n * If specified, calculates the hash of the data fetched from `uri` and matches it with provided one.\n * Yields an error upon mismatch.\n *\n * @returns {Registry} resolved registry\n */\n static async fetchMetadataRegistry(uri, contentHash) {\n if (uri.indexOf(\"https://\") < 0) {\n uri = `https://${uri}`;\n }\n // content hashes HTTPS Publication Outputs per spec\n if (contentHash) {\n // request as text and verify hash\n const response = await axios__WEBPACK_IMPORTED_MODULE_0___default().get(uri, {\n responseType: \"text\",\n transformResponse: (val) => {\n return val;\n },\n });\n const hash = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.sha256.hash((0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__.utf8ToBin)(response.data)));\n if (contentHash != hash) {\n throw new Error(`Content hash mismatch for URI: ${uri}\\nreceived: ${hash}\\nrequired: ${contentHash}`);\n }\n return JSON.parse(response.data);\n }\n // request as JSON\n const response = await axios__WEBPACK_IMPORTED_MODULE_0___default().get(uri);\n return response.data;\n }\n /**\n * addMetadataRegistry Add the metadata registry to the list of tracked registries\n *\n * @param {Registry} registry Registry object per schema specification, see https://raw.githubusercontent.com/bitjson/chip-bcmr/master/bcmr-v1.schema.json\n *\n */\n static addMetadataRegistry(registry) {\n if (this.metadataRegistries.some((val) => JSON.stringify(val) === JSON.stringify(registry))) {\n return;\n }\n this.metadataRegistries.push(registry);\n }\n /**\n * addMetadataRegistryFromUri Add the metadata registry by fetching a JSON file from a remote URI, optionally verifying its content hash\n *\n * @param {string} uri URI of the registry to fetch from\n * @param {string?} contentHash SHA256 hash of the resource the `uri` parameter points at.\n * If specified, calculates the hash of the data fetched from `uri` and matches it with provided one.\n * Yields an error upon mismatch.\n *\n */\n static async addMetadataRegistryFromUri(uri, contentHash) {\n const registry = await this.fetchMetadataRegistry(uri, contentHash);\n this.addMetadataRegistry(registry);\n }\n // helper function to enforce the constraints on the 0th output, decode the BCMR's OP_RETURN data\n // returns resolved AuthChainElement\n static makeAuthChainElement(rawTx, hash) {\n let opReturns;\n let spends0thOutput = false;\n if (rawTx.hasOwnProperty(\"vout\")) {\n const electrumTransaction = rawTx;\n opReturns = electrumTransaction.vout\n .filter((val) => val.scriptPubKey.type === \"nulldata\")\n .map((val) => val.scriptPubKey.hex);\n spends0thOutput = electrumTransaction.vin.some((val) => val.vout === 0);\n }\n else {\n const libauthTransaction = rawTx;\n opReturns = libauthTransaction.outputs\n .map((val) => (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(val.lockingBytecode))\n .filter((val) => val.indexOf(\"6a\") === 0);\n spends0thOutput = libauthTransaction.inputs.some((val) => val.outpointIndex === 0);\n }\n if (!spends0thOutput) {\n throw new Error(\"Invalid authchain transaction (does not spend 0th output of previous transaction)\");\n }\n const bcmrOpReturns = opReturns.filter((val) => val.indexOf(\"6a0442434d52\") === 0 ||\n val.indexOf(\"6a4c0442434d52\") === 0 ||\n val.indexOf(\"6a4d040042434d52\") === 0 ||\n val.indexOf(\"6a4e0400000042434d52\") === 0);\n if (bcmrOpReturns.length === 0) {\n return {\n txHash: hash,\n contentHash: \"\",\n uris: [],\n httpsUrl: \"\",\n };\n }\n const opReturnHex = opReturns[0];\n const chunks = _model_js__WEBPACK_IMPORTED_MODULE_4__.OpReturnData.parseBinary((0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.hexToBin)(opReturnHex));\n if (chunks.length < 2) {\n throw new Error(`Malformed BCMR output: ${opReturnHex}`);\n }\n const result = {\n txHash: hash,\n contentHash: \"\",\n uris: [],\n httpsUrl: \"\",\n };\n if (chunks.length === 2) {\n // IPFS Publication Output\n result.contentHash = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(chunks[1]);\n const ipfsCid = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__.binToUtf8)(chunks[1]);\n result.uris = [`ipfs://${ipfsCid}`];\n result.httpsUrl = `https://dweb.link/ipfs/${ipfsCid}`;\n }\n else {\n // URI Publication Output\n // content hash is in OP_SHA256 byte order per spec\n result.contentHash = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(chunks[1].slice());\n const uris = chunks.slice(2);\n for (const uri of uris) {\n const uriString = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__.binToUtf8)(uri);\n result.uris.push(uriString);\n if (result.httpsUrl) {\n continue;\n }\n if (uriString.indexOf(\"https://\") === 0) {\n result.httpsUrl = uriString;\n }\n else if (uriString.indexOf(\"https://\") === -1) {\n result.httpsUrl = uriString;\n // case for domain name specifier, like example.com\n if (uriString.indexOf(\"/\") === -1) {\n result.httpsUrl = `${result.httpsUrl}/.well-known/bitcoin-cash-metadata-registry.json`;\n }\n result.httpsUrl = `https://${result.httpsUrl}`;\n }\n else if (uriString.indexOf(\"ipfs://\") === 0) {\n const ipfsCid = uriString.replace(\"ipfs://\", \"\");\n result.httpsUrl = `https://dweb.link/ipfs/${ipfsCid}`;\n }\n else {\n throw new Error(`Unsupported uri type: ${uriString}`);\n }\n }\n }\n return result;\n }\n ;\n /**\n * buildAuthChain Build an authchain - Zeroth-Descendant Transaction Chain, refer to https://github.com/bitjson/chip-bcmr#zeroth-descendant-transaction-chains\n * The authchain in this implementation is specific to resolve to a valid metadata registry\n *\n * @param {string} options.transactionHash (required) transaction hash from which to build the auth chain\n * @param {Network?} options.network (default=mainnet) network to query the data from\n * @param {boolean?} options.resolveBase (default=false) boolean flag to indicate that autchain building should resolve and verify elements back to base or be stopped at this exact chain element\n * @param {boolean?} options.followToHead (default=true) boolean flag to indicate that autchain building should progress to head or be stopped at this exact chain element\n * @param {ElectrumRawTransaction?} options.rawTx cached raw transaction obtained previously, spares a Fulcrum call\n * @param {TxI[]?} options.historyCache cached address history to be reused if authchain building proceeds with the same address, spares a flurry of Fulcrum calls\n *\n * @returns {AuthChain} returns the resolved authchain\n */\n static async buildAuthChain(options) {\n if (options.network === undefined) {\n options.network = _interface_js__WEBPACK_IMPORTED_MODULE_5__.Network.MAINNET;\n }\n if (options.followToHead === undefined) {\n options.followToHead = true;\n }\n if (options.resolveBase === undefined) {\n options.resolveBase = false;\n }\n const provider = (await (0,_network_Connection_js__WEBPACK_IMPORTED_MODULE_6__.initProvider)(options.network));\n if (options.rawTx === undefined) {\n options.rawTx = await provider.getRawTransactionObject(options.transactionHash);\n }\n // figure out the autchain by moving towards authhead\n const getAuthChainChild = async () => {\n const history = options.historyCache ||\n (await provider.getHistory(options.rawTx.vout[0].scriptPubKey.addresses[0]));\n const thisTx = history.find((val) => val.tx_hash === options.transactionHash);\n let filteredHistory = history.filter((val) => val.height > 0\n ? val.height >= thisTx.height || val.height <= 0\n : val.height <= 0 && val.tx_hash !== thisTx.tx_hash);\n for (const historyTx of filteredHistory) {\n const historyRawTx = await provider.getRawTransactionObject(historyTx.tx_hash);\n const authChainVin = historyRawTx.vin.find((val) => val.txid === options.transactionHash && val.vout === 0);\n // if we've found continuation of authchain, we shall recurse into it\n if (authChainVin) {\n // reuse queried address history if the next element in chain is the same address\n const historyCache = options.rawTx.vout[0].scriptPubKey.addresses[0] ===\n historyRawTx.vout[0].scriptPubKey.addresses[0]\n ? filteredHistory\n : undefined;\n // combine the authchain element with the rest obtained\n return { rawTx: historyRawTx, historyCache };\n }\n }\n return undefined;\n };\n // make authchain element and combine with the rest obtained\n let element;\n try {\n element = BCMR.makeAuthChainElement(options.rawTx, options.rawTx.hash);\n }\n catch (error) {\n // special case for cashtoken authchain lookup by categoryId - allow to fail first lookup and inspect the genesis transaction\n // follow authchain to head and look for BCMR outputs\n const child = await getAuthChainChild();\n if (child) {\n return await BCMR.buildAuthChain({\n ...options,\n transactionHash: child.rawTx.hash,\n rawTx: child.rawTx,\n historyCache: child.historyCache,\n });\n }\n else {\n throw error;\n }\n }\n let chainBase = [];\n if (options.resolveBase) {\n // check for accelerated path if \"authchain\" extension is in registry\n const registry = await this.fetchMetadataRegistry(element.httpsUrl, element.contentHash);\n if (registry.extensions &&\n registry.extensions[\"authchain\"] &&\n Object.keys(registry.extensions[\"authchain\"]).length) {\n const chainTxArray = Object.values(registry.extensions[\"authchain\"]);\n chainBase = chainTxArray\n .map((tx) => {\n const transactionBin = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.hexToBin)(tx);\n const decoded = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_7__.decodeTransaction)(transactionBin);\n if (typeof decoded === \"string\") {\n throw new Error(`Error decoding transaction ${JSON.stringify(tx)}, ${decoded}`);\n }\n const hash = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.sha256.hash(_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.sha256.hash(transactionBin)).reverse());\n return { decoded, hash };\n })\n .map(({ decoded, hash }) => BCMR.makeAuthChainElement(decoded, hash));\n }\n else {\n // simply go back in history towards authhead\n let stop = false;\n let tx = { ...options.rawTx };\n let maxElements = 10;\n while (stop == false || maxElements === 0) {\n const vin = tx.vin.find((val) => val.vout === 0);\n tx = await provider.getRawTransactionObject(vin.txid);\n try {\n const pastElement = BCMR.makeAuthChainElement(tx, tx.hash);\n chainBase.unshift(pastElement);\n maxElements--;\n }\n catch {\n stop = true;\n }\n }\n }\n }\n // if we follow to head, we need to locate the next transaction spending our 0th output\n // and repeat the building process recursively\n if (options.followToHead) {\n const child = await getAuthChainChild();\n if (child) {\n const chainHead = await BCMR.buildAuthChain({\n transactionHash: child.rawTx.hash,\n network: options.network,\n rawTx: child.rawTx,\n historyCache: child.historyCache,\n followToHead: options.followToHead,\n resolveBase: false,\n });\n // combine the authchain element with the rest obtained\n return [...chainBase, element, ...chainHead].filter((val) => val.httpsUrl.length);\n }\n }\n // return the last chain element (or the only found in an edge case)\n return [...chainBase, element].filter((val) => val.httpsUrl.length);\n }\n /**\n * fetchAuthChainFromChaingraph Fetch the authchain information from a trusted external indexer\n * The authchain in this implementation is specific to resolve to a valid metadata registry\n *\n * @param {string} options.chaingraphUrl (required) URL of a chaingraph indexer instance to fetch info from\n * @param {string} options.transactionHash (required) transaction hash from which to build the auth chain\n * @param {string?} options.network (default=mainnet) network to query the data from, specific to the queried instance, can be mainnet, chipnet, or anything else\n *\n * @returns {AuthChain} returns the resolved authchain\n */\n static async fetchAuthChainFromChaingraph(options) {\n if (!options.chaingraphUrl) {\n throw new Error(\"Provide `chaingraphUrl` param.\");\n }\n if (options.network === undefined) {\n options.network = \"mainnet\";\n }\n const response = await axios__WEBPACK_IMPORTED_MODULE_0___default().post(options.chaingraphUrl, {\n operationName: null,\n variables: {},\n query: `{\n transaction(\n where: {\n hash:{_eq:\"\\\\\\\\x${options.transactionHash}\"},\n block_inclusions:{block:{accepted_by:{node:{name:{_ilike:\"%${options.network}%\"}}}}}\n }\n ) {\n hash\n authchains {\n authchain_length\n migrations(\n where: {\n transaction: {\n outputs: { locking_bytecode_pattern: { _like: \"6a04%\" } }\n }\n }\n ) {\n transaction {\n hash\n inputs(where:{ outpoint_index: { _eq:\"0\" } }){\n outpoint_index\n }\n outputs(where: { locking_bytecode_pattern: { _like: \"6a04%\" } }) {\n output_index\n locking_bytecode\n }\n }\n }\n }\n }\n}`\n }, {\n responseType: \"json\",\n headers: {\n Accept: \"*/*\",\n \"Content-Type\": \"application/json\",\n },\n });\n const result = [];\n const migrations = response.data.data.transaction[0]?.authchains[0].migrations;\n if (!migrations) {\n return result;\n }\n for (const migration of migrations) {\n const transaction = migration.transaction[0];\n if (!transaction) {\n continue;\n }\n transaction.inputs.forEach(input => input.outpointIndex = Number(input.outpoint_index));\n transaction.outputs.forEach(output => {\n output.outputIndex = Number(output.output_index);\n output.lockingBytecode = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.hexToBin)(output.locking_bytecode.replace(\"\\\\x\", \"\"));\n });\n const txHash = transaction.hash.replace(\"\\\\x\", \"\");\n result.push(BCMR.makeAuthChainElement(transaction, txHash));\n }\n return result;\n }\n /**\n * addMetadataRegistryAuthChain Add BCMR metadata registry by resolving an authchain\n *\n * @param {string} options.transactionHash (required) transaction hash from which to build the auth chain\n * @param {Network?} options.network (default=mainnet) network to query the data from\n * @param {boolean?} options.followToHead (default=true) boolean flag to indicate that autchain building should progress to head (most recent registry version) or be stopped at this exact chain element\n * @param {ElectrumRawTransaction?} options.rawTx cached raw transaction obtained previously, spares a Fulcrum call\n *\n * @returns {AuthChain} returns the resolved authchain\n */\n static async addMetadataRegistryAuthChain(options) {\n const authChain = await this.buildAuthChain({\n ...options,\n resolveBase: false,\n });\n if (!authChain.length) {\n throw new Error(`There were no BCMR entries in the resolved authchain ${JSON.stringify(authChain, null, 2)}`);\n }\n const registry = await this.fetchMetadataRegistry(authChain.reverse()[0].httpsUrl);\n this.addMetadataRegistry(registry);\n return authChain;\n }\n /**\n * getTokenInfo Return the token info (or the identity snapshot as per spec)\n *\n * @param {string} tokenId token id to look up\n *\n * @returns {IdentitySnapshot?} return the info for the token found, otherwise undefined\n */\n static getTokenInfo(tokenId) {\n for (const registry of this.metadataRegistries.slice().reverse()) {\n const history = registry.identities?.[tokenId];\n if (!history) {\n continue;\n }\n const latestIdentityIndex = Object.keys(history)[0];\n if (latestIdentityIndex === undefined) {\n continue;\n }\n return history[latestIdentityIndex];\n }\n return undefined;\n }\n}\n// List of tracked registries\nBCMR.metadataRegistries = [];\n\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } });\n\n//# sourceURL=webpack://mainnet-js/./src/wallet/Bcmr.ts?");
1638
1638
 
1639
1639
  /***/ }),
1640
1640
 
@@ -1,3 +1,4 @@
1
+ import { Transaction } from "@bitauth/libauth";
1
2
  import { Network, TxI } from "../interface.js";
2
3
  import { ElectrumRawTransaction } from "../network/interface.js";
3
4
  import { IdentitySnapshot, Registry } from "./bcmr-v2.schema.js";
@@ -40,6 +41,7 @@ export declare class BCMR {
40
41
  *
41
42
  */
42
43
  static addMetadataRegistryFromUri(uri: string, contentHash?: string): Promise<void>;
44
+ static makeAuthChainElement(rawTx: ElectrumRawTransaction | Transaction, hash: string): AuthChainElement;
43
45
  /**
44
46
  * buildAuthChain Build an authchain - Zeroth-Descendant Transaction Chain, refer to https://github.com/bitjson/chip-bcmr#zeroth-descendant-transaction-chains
45
47
  * The authchain in this implementation is specific to resolve to a valid metadata registry
@@ -61,6 +63,21 @@ export declare class BCMR {
61
63
  rawTx?: ElectrumRawTransaction;
62
64
  historyCache?: TxI[];
63
65
  }): Promise<AuthChain>;
66
+ /**
67
+ * fetchAuthChainFromChaingraph Fetch the authchain information from a trusted external indexer
68
+ * The authchain in this implementation is specific to resolve to a valid metadata registry
69
+ *
70
+ * @param {string} options.chaingraphUrl (required) URL of a chaingraph indexer instance to fetch info from
71
+ * @param {string} options.transactionHash (required) transaction hash from which to build the auth chain
72
+ * @param {string?} options.network (default=mainnet) network to query the data from, specific to the queried instance, can be mainnet, chipnet, or anything else
73
+ *
74
+ * @returns {AuthChain} returns the resolved authchain
75
+ */
76
+ static fetchAuthChainFromChaingraph(options: {
77
+ chaingraphUrl: string;
78
+ transactionHash: string;
79
+ network?: string;
80
+ }): Promise<AuthChain>;
64
81
  /**
65
82
  * addMetadataRegistryAuthChain Add BCMR metadata registry by resolving an authchain
66
83
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Bcmr.d.ts","sourceRoot":"","sources":["../../../src/wallet/Bcmr.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAIjE,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,oBAAY,SAAS,GAAG,gBAAgB,EAAE,CAAC;AAG3C,qBAAa,IAAI;IAEf,OAAc,kBAAkB,EAAE,QA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AM,CAAC;QACtB,eAAe,EAAE,MAAM,CAAC;QACxB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO,CAAC,SAAS,CAAC;IA2EtB;;;;;;;;;OASG;WACiB,4BAA4B,CAAC,OAAO,EAAE;QACxD,eAAe,EAAE,MAAM,CAAC;QACxB,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,KAAK,CAAC,EAAE,sBAAsB,CAAC;KAChC,GAAG,OAAO,CAAC,SAAS,CAAC;IAwBtB;;;;;;OAMG;WACW,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;CAgB1E"}
@@ -3,7 +3,7 @@ import axios from "axios";
3
3
  import { Network } from "../interface.js";
4
4
  import { initProvider } from "../network/Connection.js";
5
5
  import { OpReturnData } from "./model.js";
6
- // Implementation of CHIP-BCMR v1.0.0, refer to https://github.com/bitjson/chip-bcmr
6
+ // Implementation of CHIP-BCMR v2.0.0-draft, refer to https://github.com/bitjson/chip-bcmr
7
7
  export class BCMR {
8
8
  static getRegistries() {
9
9
  return this.metadataRegistries;
@@ -69,6 +69,92 @@ export class BCMR {
69
69
  const registry = await this.fetchMetadataRegistry(uri, contentHash);
70
70
  this.addMetadataRegistry(registry);
71
71
  }
72
+ // helper function to enforce the constraints on the 0th output, decode the BCMR's OP_RETURN data
73
+ // returns resolved AuthChainElement
74
+ static makeAuthChainElement(rawTx, hash) {
75
+ let opReturns;
76
+ let spends0thOutput = false;
77
+ if (rawTx.hasOwnProperty("vout")) {
78
+ const electrumTransaction = rawTx;
79
+ opReturns = electrumTransaction.vout
80
+ .filter((val) => val.scriptPubKey.type === "nulldata")
81
+ .map((val) => val.scriptPubKey.hex);
82
+ spends0thOutput = electrumTransaction.vin.some((val) => val.vout === 0);
83
+ }
84
+ else {
85
+ const libauthTransaction = rawTx;
86
+ opReturns = libauthTransaction.outputs
87
+ .map((val) => binToHex(val.lockingBytecode))
88
+ .filter((val) => val.indexOf("6a") === 0);
89
+ spends0thOutput = libauthTransaction.inputs.some((val) => val.outpointIndex === 0);
90
+ }
91
+ if (!spends0thOutput) {
92
+ throw new Error("Invalid authchain transaction (does not spend 0th output of previous transaction)");
93
+ }
94
+ const bcmrOpReturns = opReturns.filter((val) => val.indexOf("6a0442434d52") === 0 ||
95
+ val.indexOf("6a4c0442434d52") === 0 ||
96
+ val.indexOf("6a4d040042434d52") === 0 ||
97
+ val.indexOf("6a4e0400000042434d52") === 0);
98
+ if (bcmrOpReturns.length === 0) {
99
+ return {
100
+ txHash: hash,
101
+ contentHash: "",
102
+ uris: [],
103
+ httpsUrl: "",
104
+ };
105
+ }
106
+ const opReturnHex = opReturns[0];
107
+ const chunks = OpReturnData.parseBinary(hexToBin(opReturnHex));
108
+ if (chunks.length < 2) {
109
+ throw new Error(`Malformed BCMR output: ${opReturnHex}`);
110
+ }
111
+ const result = {
112
+ txHash: hash,
113
+ contentHash: "",
114
+ uris: [],
115
+ httpsUrl: "",
116
+ };
117
+ if (chunks.length === 2) {
118
+ // IPFS Publication Output
119
+ result.contentHash = binToHex(chunks[1]);
120
+ const ipfsCid = binToUtf8(chunks[1]);
121
+ result.uris = [`ipfs://${ipfsCid}`];
122
+ result.httpsUrl = `https://dweb.link/ipfs/${ipfsCid}`;
123
+ }
124
+ else {
125
+ // URI Publication Output
126
+ // content hash is in OP_SHA256 byte order per spec
127
+ result.contentHash = binToHex(chunks[1].slice());
128
+ const uris = chunks.slice(2);
129
+ for (const uri of uris) {
130
+ const uriString = binToUtf8(uri);
131
+ result.uris.push(uriString);
132
+ if (result.httpsUrl) {
133
+ continue;
134
+ }
135
+ if (uriString.indexOf("https://") === 0) {
136
+ result.httpsUrl = uriString;
137
+ }
138
+ else if (uriString.indexOf("https://") === -1) {
139
+ result.httpsUrl = uriString;
140
+ // case for domain name specifier, like example.com
141
+ if (uriString.indexOf("/") === -1) {
142
+ result.httpsUrl = `${result.httpsUrl}/.well-known/bitcoin-cash-metadata-registry.json`;
143
+ }
144
+ result.httpsUrl = `https://${result.httpsUrl}`;
145
+ }
146
+ else if (uriString.indexOf("ipfs://") === 0) {
147
+ const ipfsCid = uriString.replace("ipfs://", "");
148
+ result.httpsUrl = `https://dweb.link/ipfs/${ipfsCid}`;
149
+ }
150
+ else {
151
+ throw new Error(`Unsupported uri type: ${uriString}`);
152
+ }
153
+ }
154
+ }
155
+ return result;
156
+ }
157
+ ;
72
158
  /**
73
159
  * buildAuthChain Build an authchain - Zeroth-Descendant Transaction Chain, refer to https://github.com/bitjson/chip-bcmr#zeroth-descendant-transaction-chains
74
160
  * The authchain in this implementation is specific to resolve to a valid metadata registry
@@ -120,95 +206,10 @@ export class BCMR {
120
206
  }
121
207
  return undefined;
122
208
  };
123
- // helper function to enforce the constraints on the 0th output, decode the BCMR's OP_RETURN data
124
- // returns resolved AuthChainElement
125
- const makeAuthChainElement = (rawTx, hash) => {
126
- let opReturns;
127
- let spends0thOutput = false;
128
- if (rawTx.hasOwnProperty("vout")) {
129
- const electrumTransaction = rawTx;
130
- opReturns = electrumTransaction.vout
131
- .filter((val) => val.scriptPubKey.type === "nulldata")
132
- .map((val) => val.scriptPubKey.hex);
133
- spends0thOutput = electrumTransaction.vin.some((val) => val.vout === 0);
134
- }
135
- else {
136
- const libauthTransaction = rawTx;
137
- opReturns = libauthTransaction.outputs
138
- .map((val) => binToHex(val.lockingBytecode))
139
- .filter((val) => val.indexOf("6a") === 0);
140
- spends0thOutput = libauthTransaction.inputs.some((val) => val.outpointIndex === 0);
141
- }
142
- if (!spends0thOutput) {
143
- throw new Error("Invalid authchain transaction (does not spend 0th output of previous transaction)");
144
- }
145
- const bcmrOpReturns = opReturns.filter((val) => val.indexOf("6a0442434d52") === 0 ||
146
- val.indexOf("6a4c0442434d52") === 0 ||
147
- val.indexOf("6a4d040042434d52") === 0 ||
148
- val.indexOf("6a4e0400000042434d52") === 0);
149
- if (bcmrOpReturns.length === 0) {
150
- return {
151
- txHash: hash,
152
- contentHash: "",
153
- uris: [],
154
- httpsUrl: "",
155
- };
156
- }
157
- const opReturnHex = opReturns[0];
158
- const chunks = OpReturnData.parseBinary(hexToBin(opReturnHex));
159
- if (chunks.length < 2) {
160
- throw new Error(`Malformed BCMR output: ${opReturnHex}`);
161
- }
162
- const result = {
163
- txHash: hash,
164
- contentHash: "",
165
- uris: [],
166
- httpsUrl: "",
167
- };
168
- if (chunks.length === 2) {
169
- // IPFS Publication Output
170
- result.contentHash = binToHex(chunks[1]);
171
- const ipfsCid = binToUtf8(chunks[1]);
172
- result.uris = [`ipfs://${ipfsCid}`];
173
- result.httpsUrl = `https://dweb.link/ipfs/${ipfsCid}`;
174
- }
175
- else {
176
- // URI Publication Output
177
- // content hash is in OP_SHA256 byte order per spec
178
- result.contentHash = binToHex(chunks[1].slice());
179
- const uris = chunks.slice(2);
180
- for (const uri of uris) {
181
- const uriString = binToUtf8(uri);
182
- result.uris.push(uriString);
183
- if (result.httpsUrl) {
184
- continue;
185
- }
186
- if (uriString.indexOf("https://") === 0) {
187
- result.httpsUrl = uriString;
188
- }
189
- else if (uriString.indexOf("https://") === -1) {
190
- result.httpsUrl = uriString;
191
- // case for domain name specifier, like example.com
192
- if (uriString.indexOf("/") === -1) {
193
- result.httpsUrl = `${result.httpsUrl}/.well-known/bitcoin-cash-metadata-registry.json`;
194
- }
195
- result.httpsUrl = `https://${result.httpsUrl}`;
196
- }
197
- else if (uriString.indexOf("ipfs://") === 0) {
198
- const ipfsCid = uriString.replace("ipfs://", "");
199
- result.httpsUrl = `https://dweb.link/ipfs/${ipfsCid}`;
200
- }
201
- else {
202
- throw new Error(`Unsupported uri type: ${uriString}`);
203
- }
204
- }
205
- }
206
- return result;
207
- };
208
209
  // make authchain element and combine with the rest obtained
209
210
  let element;
210
211
  try {
211
- element = makeAuthChainElement(options.rawTx, options.rawTx.hash);
212
+ element = BCMR.makeAuthChainElement(options.rawTx, options.rawTx.hash);
212
213
  }
213
214
  catch (error) {
214
215
  // special case for cashtoken authchain lookup by categoryId - allow to fail first lookup and inspect the genesis transaction
@@ -244,7 +245,7 @@ export class BCMR {
244
245
  const hash = binToHex(sha256.hash(sha256.hash(transactionBin)).reverse());
245
246
  return { decoded, hash };
246
247
  })
247
- .map(({ decoded, hash }) => makeAuthChainElement(decoded, hash));
248
+ .map(({ decoded, hash }) => BCMR.makeAuthChainElement(decoded, hash));
248
249
  }
249
250
  else {
250
251
  // simply go back in history towards authhead
@@ -255,7 +256,7 @@ export class BCMR {
255
256
  const vin = tx.vin.find((val) => val.vout === 0);
256
257
  tx = await provider.getRawTransactionObject(vin.txid);
257
258
  try {
258
- const pastElement = makeAuthChainElement(tx, tx.hash);
259
+ const pastElement = BCMR.makeAuthChainElement(tx, tx.hash);
259
260
  chainBase.unshift(pastElement);
260
261
  maxElements--;
261
262
  }
@@ -285,6 +286,84 @@ export class BCMR {
285
286
  // return the last chain element (or the only found in an edge case)
286
287
  return [...chainBase, element].filter((val) => val.httpsUrl.length);
287
288
  }
289
+ /**
290
+ * fetchAuthChainFromChaingraph Fetch the authchain information from a trusted external indexer
291
+ * The authchain in this implementation is specific to resolve to a valid metadata registry
292
+ *
293
+ * @param {string} options.chaingraphUrl (required) URL of a chaingraph indexer instance to fetch info from
294
+ * @param {string} options.transactionHash (required) transaction hash from which to build the auth chain
295
+ * @param {string?} options.network (default=mainnet) network to query the data from, specific to the queried instance, can be mainnet, chipnet, or anything else
296
+ *
297
+ * @returns {AuthChain} returns the resolved authchain
298
+ */
299
+ static async fetchAuthChainFromChaingraph(options) {
300
+ if (!options.chaingraphUrl) {
301
+ throw new Error("Provide `chaingraphUrl` param.");
302
+ }
303
+ if (options.network === undefined) {
304
+ options.network = "mainnet";
305
+ }
306
+ const response = await axios.post(options.chaingraphUrl, {
307
+ operationName: null,
308
+ variables: {},
309
+ query: `{
310
+ transaction(
311
+ where: {
312
+ hash:{_eq:"\\\\x${options.transactionHash}"},
313
+ block_inclusions:{block:{accepted_by:{node:{name:{_ilike:"%${options.network}%"}}}}}
314
+ }
315
+ ) {
316
+ hash
317
+ authchains {
318
+ authchain_length
319
+ migrations(
320
+ where: {
321
+ transaction: {
322
+ outputs: { locking_bytecode_pattern: { _like: "6a04%" } }
323
+ }
324
+ }
325
+ ) {
326
+ transaction {
327
+ hash
328
+ inputs(where:{ outpoint_index: { _eq:"0" } }){
329
+ outpoint_index
330
+ }
331
+ outputs(where: { locking_bytecode_pattern: { _like: "6a04%" } }) {
332
+ output_index
333
+ locking_bytecode
334
+ }
335
+ }
336
+ }
337
+ }
338
+ }
339
+ }`
340
+ }, {
341
+ responseType: "json",
342
+ headers: {
343
+ Accept: "*/*",
344
+ "Content-Type": "application/json",
345
+ },
346
+ });
347
+ const result = [];
348
+ const migrations = response.data.data.transaction[0]?.authchains[0].migrations;
349
+ if (!migrations) {
350
+ return result;
351
+ }
352
+ for (const migration of migrations) {
353
+ const transaction = migration.transaction[0];
354
+ if (!transaction) {
355
+ continue;
356
+ }
357
+ transaction.inputs.forEach(input => input.outpointIndex = Number(input.outpoint_index));
358
+ transaction.outputs.forEach(output => {
359
+ output.outputIndex = Number(output.output_index);
360
+ output.lockingBytecode = hexToBin(output.locking_bytecode.replace("\\x", ""));
361
+ });
362
+ const txHash = transaction.hash.replace("\\x", "");
363
+ result.push(BCMR.makeAuthChainElement(transaction, txHash));
364
+ }
365
+ return result;
366
+ }
288
367
  /**
289
368
  * addMetadataRegistryAuthChain Add BCMR metadata registry by resolving an authchain
290
369
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Bcmr.js","sourceRoot":"","sources":["../../../src/wallet/Bcmr.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAER,SAAS,EACT,iBAAiB,EACjB,QAAQ,EACR,MAAM,EAEN,SAAS,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAO,MAAM,iBAAiB,CAAC;AAI/C,OAAO,EAAE,YAAY,EAAE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