dotbit
Version:
A complete .bit SDK and utilities in TypeScript
97 lines • 5.31 kB
JavaScript
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;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BitSubAccount = void 0;
const BitAccount_1 = require("./BitAccount");
const RegisterAPI_1 = require("./fetchers/RegisterAPI");
const DotbitError_1 = require("./errors/DotbitError");
const account_1 = require("./tools/account");
class BitSubAccount extends BitAccount_1.BitAccount {
constructor(options) {
super(options);
_BitSubAccount_instances.add(this);
this.isSubAccount = true;
if (!(0, account_1.isSubAccount)(options.account)) {
throw new DotbitError_1.DotbitError(`${options.account} is not a legit Second-level DID`, DotbitError_1.BitErrorCode.InvalidSubAccount);
}
this.mainAccount = this.account.replace(/^.+?\./, '');
}
subAccounts(params = { page: 1, size: 100, keyword: '' }) {
throw new DotbitError_1.DotbitError(`'subAccounts' is not supported by Second-level DID ${this.account}`, DotbitError_1.BitErrorCode.SubAccountDoNotSupportSubAccount);
}
checkSubAccounts(subAccounts) {
throw new DotbitError_1.DotbitError(`'checkSubAccounts' is not supported by Second-level DID ${this.account}`, DotbitError_1.BitErrorCode.SubAccountDoNotSupportSubAccount);
}
mintSubAccounts() {
throw new DotbitError_1.DotbitError(`'mintSubAccounts' is not supported by Second-level DID ${this.account}`, DotbitError_1.BitErrorCode.SubAccountDoNotSupportSubAccount);
}
mintSubAccount() {
throw new DotbitError_1.DotbitError(`'mintSubAccount' is not supported by Second-level DID ${this.account}`, DotbitError_1.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(RegisterAPI_1.toEditingRecord), 'records');
}
}
exports.BitSubAccount = BitSubAccount;
_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
;