UNPKG

@radixdlt/atom

Version:

Container for CRUD instructions known as 'Particles' that are sent to the Radix decentralized ledger

25 lines 1.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AtomIdentifier = void 0; const neverthrow_1 = require("neverthrow"); const util_1 = require("@radixdlt/util"); const data_formats_1 = require("@radixdlt/data-formats"); const CBOR_BYTESTRING_PREFIX = 6; const JSONDecoder = data_formats_1.decoder((value, key) => key === 'atomIdentifier' && util_1.isString(value) ? create(value) : undefined); const create = (bytes) => { const buffer = typeof bytes === 'string' ? Buffer.from(bytes, 'hex') : bytes; const length = 32; if (buffer.length !== length) { return neverthrow_1.err(new Error(`Expected #${length} bytes, but got #${buffer.length}`)); } const asString = buffer.toString('hex'); return neverthrow_1.ok(Object.assign(Object.assign({}, data_formats_1.DSONObjectEncoding({ prefix: CBOR_BYTESTRING_PREFIX, buffer, })), { toString: () => asString, equals: (other) => other.toString() === asString })); }; exports.AtomIdentifier = { create, JSONDecoder, }; //# sourceMappingURL=atomIdentifier.js.map