@ngraveio/ur-blockchain-commons
Version:
A JS implementation of Uniform Resources(UR) Registry specification from Blockchain Commons.
77 lines (71 loc) • 2.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoinInfo = exports.Network = void 0;
const bc_ur_1 = require("@ngraveio/bc-ur");
var Network;
(function (Network) {
Network[Network["mainnet"] = 0] = "mainnet";
Network[Network["testnet"] = 1] = "testnet";
})(Network || (exports.Network = Network = {}));
class CoinInfo extends (0, bc_ur_1.registryItemFactory)({
tag: 40305,
URType: 'coin-info',
keyMap: {
type: 1,
network: 2,
},
CDDL: `
; Metadata for the type and use of a cryptocurrency
tagged-coininfo = #6.40305(coininfo)
coininfo = {
? type: uint31 .default cointype-btc, ; values from [SLIP44](https://github.com/satoshilabs/slips/blob/master/slip-0044.md) with high bit turned off
? network: int .default mainnet ; coin-specific identifier for testnet
}
type = 1
network = 2
cointype-btc = 0
cointype-eth = 0x3c
mainnet = 0;
testnet-btc = 1;
; from [ETH-TEST-NETWORKS]
testnet-eth-ropsten = 1;
testnet-eth-kovan = 2;
testnet-eth-rinkeby = 3;
testnet-eth-gorli = 4;
`,
}) {
constructor(type, network) {
// Pass an data object
super({ type, network });
this.getType = () => this.data.type || 0;
this.getNetwork = () => this.data.network || 0;
this.data = { type, network };
}
verifyInput(input) {
// Check if type is integer and bigger than 0
if (input.type !== undefined && (typeof input.type !== 'number' || input.type < 0)) {
return {
valid: false,
reasons: [new Error('Type must be a positive integer')],
};
}
if (input.network !== undefined && (typeof input.network !== 'number' || input.network < 0)) {
return {
valid: false,
reasons: [new Error('Network must be a positive integer')],
};
}
return { valid: true };
}
/**
* We need to override this method because class expects 2 arguments instead of an object
*/
static fromCBORData(val, allowKeysNotInMap = false, tagged) {
// Do some post processing data coming from the cbor decoder
const data = this.postCBOR(val, allowKeysNotInMap);
// Return an instance of the generated class
return new this(data.type, data.network);
}
}
exports.CoinInfo = CoinInfo;
//# sourceMappingURL=CoinInfo.js.map