@ngraveio/ur-sync
Version:
Provides BC-UR types for syncing multiple coins and accounts from cold wallets to watch only wallets.
55 lines (53 loc) • 1.96 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Portfolio = void 0;
const bc_ur_1 = require("@ngraveio/bc-ur");
const PortfolioCoin_1 = require("./PortfolioCoin");
const PortfolioMetadata_1 = require("./PortfolioMetadata");
class Portfolio extends (0, bc_ur_1.registryItemFactory)({
tag: 41405,
URType: 'portfolio',
keyMap: {
coins: 1,
metadata: 2,
},
allowKeysNotInMap: false,
CDDL: `
; Top level multi coin sync payload
sync = {
coins: [+ #6.41403(portfolio-coin)], ; Multiple coins with their respective accounts and coin identities
? metadata: #6.41404(portfolio-metadata) ; Optional wallet metadata
}
coins = 1
metadata = 2
`,
}) {
constructor(data) {
super(data);
this.getCoins = () => this.data.coins;
this.getMetadata = () => this.data.metadata;
this.data = data;
}
verifyInput(input) {
const errors = [];
// Type check
if (input.coins == undefined || !Array.isArray(input.coins)) {
errors.push(new Error('Coins must be an array'));
}
// Check if coins is an array of PortfolioCoin
if (input.coins && !input.coins.every((coin) => coin instanceof PortfolioCoin_1.PortfolioCoin)) {
errors.push(new Error('Coins must be an array of PortfolioCoin'));
}
// Check if metadata is of type PortfolioMetadata
if (input.metadata && !(input.metadata instanceof PortfolioMetadata_1.PortfolioMetadata)) {
errors.push(new Error('Metadata must be of type PortfolioMetadata'));
}
// TODO: Check for the metadata master fingerprint aligns with the coins master fingerprint
return {
valid: errors.length === 0,
reasons: errors.length > 0 ? errors : undefined,
};
}
}
exports.Portfolio = Portfolio;
//# sourceMappingURL=Portfolio.js.map