UNPKG

dotbit

Version:

A complete .bit SDK and utilities in TypeScript

93 lines 5 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _BitSubAccount_instances, _BitSubAccount_editSubAccount; import { BitAccount } from './BitAccount'; import { toEditingRecord } from './fetchers/RegisterAPI'; import { BitErrorCode, DotbitError } from './errors/DotbitError'; import { isSubAccount } from './tools/account'; export class BitSubAccount extends BitAccount { constructor(options) { super(options); _BitSubAccount_instances.add(this); this.isSubAccount = true; if (!isSubAccount(options.account)) { throw new DotbitError(`${options.account} is not a legit Second-level DID`, BitErrorCode.InvalidSubAccount); } this.mainAccount = this.account.replace(/^.+?\./, ''); } subAccounts(params = { page: 1, size: 100, keyword: '' }) { throw new DotbitError(`'subAccounts' is not supported by Second-level DID ${this.account}`, BitErrorCode.SubAccountDoNotSupportSubAccount); } checkSubAccounts(subAccounts) { throw new DotbitError(`'checkSubAccounts' is not supported by Second-level DID ${this.account}`, BitErrorCode.SubAccountDoNotSupportSubAccount); } mintSubAccounts() { throw new DotbitError(`'mintSubAccounts' is not supported by Second-level DID ${this.account}`, BitErrorCode.SubAccountDoNotSupportSubAccount); } mintSubAccount() { throw new DotbitError(`'mintSubAccount' is not supported by Second-level DID ${this.account}`, BitErrorCode.SubAccountDoNotSupportSubAccount); } changeOwner(keyInfo) { return __classPrivateFieldGet(this, _BitSubAccount_instances, "m", _BitSubAccount_editSubAccount).call(this, keyInfo, 'owner'); } changeManager(keyInfo) { return __classPrivateFieldGet(this, _BitSubAccount_instances, "m", _BitSubAccount_editSubAccount).call(this, keyInfo, 'manager'); } updateRecords(records) { return __classPrivateFieldGet(this, _BitSubAccount_instances, "m", _BitSubAccount_editSubAccount).call(this, records.map(toEditingRecord), 'records'); } } _BitSubAccount_instances = new WeakSet(), _BitSubAccount_editSubAccount = function _BitSubAccount_editSubAccount(value, editKey) { return __awaiter(this, void 0, void 0, function* () { const signerAddress = yield this.signer.getAddress(); const signerCoinType = yield this.signer.getCoinType(); const currentInfo = { account: this.account, type: 'blockchain', key_info: { key: signerAddress, coin_type: signerCoinType, }, }; let mmJsonTxs = {}; if (editKey === 'owner') { value = value; mmJsonTxs = yield this.bitBuilder.editSubAccount(Object.assign(Object.assign({}, currentInfo), { edit_key: 'owner', edit_value: { owner: { type: 'blockchain', key_info: value } } })); } else if (editKey === 'manager') { value = value; mmJsonTxs = yield this.bitBuilder.editSubAccount(Object.assign(Object.assign({}, currentInfo), { edit_key: 'manager', edit_value: { manager: { type: 'blockchain', key_info: value } } })); } else if (editKey === 'records') { value = value; mmJsonTxs = yield this.bitBuilder.editSubAccount(Object.assign(Object.assign({}, currentInfo), { edit_key: 'records', edit_value: { records: value } })); } const signatureList = yield this.signer.signTxList(mmJsonTxs); return yield this.bitBuilder.subAccountAPI.sendTransaction(signatureList); }); }; //# sourceMappingURL=BitSubAccount.js.map