@okxweb3/coin-stellar
Version:
@ok/coin-stellar is a Stellar SDK for building Web3 wallets and applications. It supports Stellar and PI blockchains, enabling private key management, address generation, transaction signing, trustline creation, and asset transfers
60 lines • 2.29 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MuxedAccount = void 0;
const xdr_1 = __importDefault(require("./xdr"));
const account_1 = require("./account");
const strkey_1 = require("./strkey");
const decode_encode_muxed_account_1 = require("./util/decode_encode_muxed_account");
class MuxedAccount {
constructor(baseAccount, id) {
const accountId = baseAccount.accountId();
if (!strkey_1.StrKey.isValidEd25519PublicKey(accountId)) {
throw new Error('accountId is invalid');
}
this.account = baseAccount;
this._muxedXdr = (0, decode_encode_muxed_account_1.encodeMuxedAccount)(accountId, id);
this._mAddress = (0, decode_encode_muxed_account_1.encodeMuxedAccountToAddress)(this._muxedXdr);
this._id = id;
}
static fromAddress(mAddress, sequenceNum) {
const muxedAccount = (0, decode_encode_muxed_account_1.decodeAddressToMuxedAccount)(mAddress);
const gAddress = (0, decode_encode_muxed_account_1.extractBaseAddress)(mAddress);
const id = muxedAccount.med25519().id().toString();
return new MuxedAccount(new account_1.Account(gAddress, sequenceNum), id);
}
baseAccount() {
return this.account;
}
accountId() {
return this._mAddress;
}
id() {
return this._id;
}
setId(id) {
if (typeof id !== 'string') {
throw new Error('id should be a string representing a number (uint64)');
}
this._muxedXdr.med25519().id(xdr_1.default.Uint64.fromString(id));
this._mAddress = (0, decode_encode_muxed_account_1.encodeMuxedAccountToAddress)(this._muxedXdr);
this._id = id;
return this;
}
sequenceNumber() {
return this.account.sequenceNumber();
}
incrementSequenceNumber() {
return this.account.incrementSequenceNumber();
}
toXDRObject() {
return this._muxedXdr;
}
equals(otherMuxedAccount) {
return this.accountId() === otherMuxedAccount.accountId();
}
}
exports.MuxedAccount = MuxedAccount;
//# sourceMappingURL=muxed_account.js.map