UNPKG

client-aftermath-ts-sdk

Version:
40 lines (39 loc) 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MultisigApi = void 0; const multisig_1 = require("@mysten/sui/multisig"); const ed25519_1 = require("@mysten/sui/keypairs/ed25519"); class MultisigApi { // ========================================================================= // Constructor // ========================================================================= constructor(Provider) { this.Provider = Provider; const sharedCustodyAddresses = this.Provider.addresses.sharedCustody; if (!sharedCustodyAddresses) throw new Error("not all required addresses have been set in provider"); this.sharedCustodyAddresses = sharedCustodyAddresses; } // ========================================================================= // Fetch // ========================================================================= getMultisigForUser(inputs) { const afPublicKeyBuffer = Buffer.from(this.sharedCustodyAddresses.publicKey || "", "base64"); // MARK: Shifting the first byte const afPublicKeyArray = new Uint8Array(afPublicKeyBuffer).subarray(1); const afPK = new ed25519_1.Ed25519PublicKey(afPublicKeyArray); const userPK = new ed25519_1.Ed25519PublicKey(inputs.userPublicKey); const newMultiSigPublicKey = multisig_1.MultiSigPublicKey.fromPublicKeys({ threshold: 1, publicKeys: [ { publicKey: afPK, weight: 1 }, { publicKey: userPK, weight: 1 }, ], }); return { publicKey: newMultiSigPublicKey, address: newMultiSigPublicKey.toSuiAddress(), }; } } exports.MultisigApi = MultisigApi;