@scallop-io/sui-kit
Advanced tools
Comparing version 0.42.0 to 0.42.1
@@ -24,2 +24,3 @@ "use strict"; | ||
__export(src_exports, { | ||
MultiSigClient: () => MultiSigClient, | ||
SuiAccountManager: () => SuiAccountManager, | ||
@@ -788,4 +789,600 @@ SuiKit: () => SuiKit, | ||
}; | ||
// src/libs/multiSig/multiSig.ts | ||
var import_blake2b = require("@noble/hashes/blake2b"); | ||
var import_utils6 = require("@noble/hashes/utils"); | ||
var import_ed255193 = require("@mysten/sui.js/keypairs/ed25519"); | ||
var import_secp256r1 = require("@mysten/sui.js/keypairs/secp256r1"); | ||
var import_secp256k1 = require("@mysten/sui.js/keypairs/secp256k1"); | ||
var import_multisig = require("@mysten/sui.js/multisig"); | ||
var import_utils7 = require("@mysten/sui.js/utils"); | ||
var import_cryptography = require("@mysten/sui.js/cryptography"); | ||
// src/libs/bcs/bcs.ts | ||
var import_bcs2 = require("@mysten/bcs"); | ||
var import_utils5 = require("@mysten/sui.js/utils"); | ||
// src/libs/bcs/typeTagSerializer.ts | ||
var import_bcs = require("@mysten/bcs"); | ||
var import_utils4 = require("@mysten/sui.js/utils"); | ||
var VECTOR_REGEX = /^vector<(.+)>$/; | ||
var STRUCT_REGEX = /^([^:]+)::([^:]+)::([^<]+)(<(.+)>)?/; | ||
var TypeTagSerializer = class _TypeTagSerializer { | ||
static parseFromStr(str, normalizeAddress = false) { | ||
if (str === "address") { | ||
return { address: null }; | ||
} else if (str === "bool") { | ||
return { bool: null }; | ||
} else if (str === "u8") { | ||
return { u8: null }; | ||
} else if (str === "u16") { | ||
return { u16: null }; | ||
} else if (str === "u32") { | ||
return { u32: null }; | ||
} else if (str === "u64") { | ||
return { u64: null }; | ||
} else if (str === "u128") { | ||
return { u128: null }; | ||
} else if (str === "u256") { | ||
return { u256: null }; | ||
} else if (str === "signer") { | ||
return { signer: null }; | ||
} | ||
const vectorMatch = str.match(VECTOR_REGEX); | ||
if (vectorMatch) { | ||
return { | ||
vector: _TypeTagSerializer.parseFromStr( | ||
vectorMatch[1], | ||
normalizeAddress | ||
) | ||
}; | ||
} | ||
const structMatch = str.match(STRUCT_REGEX); | ||
if (structMatch) { | ||
const address = normalizeAddress ? (0, import_utils4.normalizeSuiAddress)(structMatch[1]) : structMatch[1]; | ||
return { | ||
struct: { | ||
address, | ||
module: structMatch[2], | ||
name: structMatch[3], | ||
typeParams: structMatch[5] === void 0 ? [] : _TypeTagSerializer.parseStructTypeArgs( | ||
structMatch[5], | ||
normalizeAddress | ||
) | ||
} | ||
}; | ||
} | ||
throw new Error( | ||
`Encountered unexpected token when parsing type args for ${str}` | ||
); | ||
} | ||
static parseStructTypeArgs(str, normalizeAddress = false) { | ||
return (0, import_bcs.splitGenericParameters)(str).map( | ||
(tok) => _TypeTagSerializer.parseFromStr(tok, normalizeAddress) | ||
); | ||
} | ||
static tagToString(tag) { | ||
if ("bool" in tag) { | ||
return "bool"; | ||
} | ||
if ("u8" in tag) { | ||
return "u8"; | ||
} | ||
if ("u16" in tag) { | ||
return "u16"; | ||
} | ||
if ("u32" in tag) { | ||
return "u32"; | ||
} | ||
if ("u64" in tag) { | ||
return "u64"; | ||
} | ||
if ("u128" in tag) { | ||
return "u128"; | ||
} | ||
if ("u256" in tag) { | ||
return "u256"; | ||
} | ||
if ("address" in tag) { | ||
return "address"; | ||
} | ||
if ("signer" in tag) { | ||
return "signer"; | ||
} | ||
if ("vector" in tag) { | ||
return `vector<${_TypeTagSerializer.tagToString(tag.vector)}>`; | ||
} | ||
if ("struct" in tag) { | ||
const struct = tag.struct; | ||
const typeParams = struct.typeParams.map(_TypeTagSerializer.tagToString).join(", "); | ||
return `${struct.address}::${struct.module}::${struct.name}${typeParams ? `<${typeParams}>` : ""}`; | ||
} | ||
throw new Error("Invalid TypeTag"); | ||
} | ||
}; | ||
// src/libs/bcs/bcs.ts | ||
var bcsRegistry = new import_bcs2.BCS({ ...(0, import_bcs2.getSuiMoveConfig)() }); | ||
function unsafe_u64(options) { | ||
return import_bcs2.bcs.u64({ | ||
name: "unsafe_u64", | ||
...options | ||
}).transform({ | ||
input: (val) => val, | ||
output: (val) => Number(val) | ||
}); | ||
} | ||
function optionEnum(type) { | ||
return import_bcs2.bcs.enum("Option", { | ||
None: null, | ||
Some: type | ||
}); | ||
} | ||
function enumKind(type) { | ||
return type.transform({ | ||
input: (val) => ({ | ||
[val.kind]: val | ||
}), | ||
output: (val) => { | ||
const key = Object.keys(val)[0]; | ||
return { kind: key, ...val[key] }; | ||
} | ||
}); | ||
} | ||
var Address = import_bcs2.bcs.bytes(import_utils5.SUI_ADDRESS_LENGTH).transform({ | ||
input: (val) => typeof val === "string" ? (0, import_bcs2.fromHEX)(val) : val, | ||
output: (val) => (0, import_bcs2.toHEX)(val) | ||
}); | ||
var ObjectDigest = import_bcs2.bcs.vector(import_bcs2.bcs.u8()).transform({ | ||
name: "ObjectDigest", | ||
input: (value) => (0, import_bcs2.fromB58)(value), | ||
output: (value) => (0, import_bcs2.toB58)(new Uint8Array(value)) | ||
}); | ||
var SuiObjectRef = import_bcs2.bcs.struct("SuiObjectRef", { | ||
objectId: Address, | ||
version: import_bcs2.bcs.u64(), | ||
digest: ObjectDigest | ||
}); | ||
var SharedObjectRef = import_bcs2.bcs.struct("SharedObjectRef", { | ||
objectId: Address, | ||
initialSharedVersion: import_bcs2.bcs.u64(), | ||
mutable: import_bcs2.bcs.bool() | ||
}); | ||
var ObjectArg = import_bcs2.bcs.enum("ObjectArg", { | ||
ImmOrOwned: SuiObjectRef, | ||
Shared: SharedObjectRef | ||
}); | ||
var CallArg = import_bcs2.bcs.enum("CallArg", { | ||
Pure: import_bcs2.bcs.vector(import_bcs2.bcs.u8()), | ||
Object: ObjectArg, | ||
ObjVec: import_bcs2.bcs.vector(ObjectArg) | ||
}); | ||
var TypeTag = import_bcs2.bcs.enum("TypeTag", { | ||
bool: null, | ||
u8: null, | ||
u64: null, | ||
u128: null, | ||
address: null, | ||
signer: null, | ||
vector: import_bcs2.bcs.lazy(() => TypeTag), | ||
struct: import_bcs2.bcs.lazy(() => StructTag), | ||
u16: null, | ||
u32: null, | ||
u256: null | ||
}); | ||
var Argument = enumKind( | ||
import_bcs2.bcs.enum("Argument", { | ||
GasCoin: null, | ||
Input: import_bcs2.bcs.struct("Input", { index: import_bcs2.bcs.u16() }), | ||
Result: import_bcs2.bcs.struct("Result", { index: import_bcs2.bcs.u16() }), | ||
NestedResult: import_bcs2.bcs.struct("NestedResult", { | ||
index: import_bcs2.bcs.u16(), | ||
resultIndex: import_bcs2.bcs.u16() | ||
}) | ||
}) | ||
); | ||
var ProgrammableMoveCall = import_bcs2.bcs.struct("ProgrammableMoveCall", { | ||
package: Address, | ||
module: import_bcs2.bcs.string(), | ||
function: import_bcs2.bcs.string(), | ||
type_arguments: import_bcs2.bcs.vector(TypeTag), | ||
arguments: import_bcs2.bcs.vector(Argument) | ||
}).transform({ | ||
// TODO: add type for the input data | ||
input: (data) => { | ||
const [pkg, module2, fun] = data.target.split("::"); | ||
const type_arguments = data.typeArguments.map( | ||
(tag) => TypeTagSerializer.parseFromStr(tag, true) | ||
); | ||
return { | ||
package: (0, import_utils5.normalizeSuiAddress)(pkg), | ||
module: module2, | ||
function: fun, | ||
type_arguments, | ||
arguments: data.arguments | ||
}; | ||
}, | ||
output: (data) => { | ||
return { | ||
target: [data.package, data.module, data.function].join( | ||
"::" | ||
), | ||
arguments: data.arguments, | ||
typeArguments: data.type_arguments.map(TypeTagSerializer.tagToString) | ||
}; | ||
} | ||
}); | ||
var Transaction = enumKind( | ||
import_bcs2.bcs.enum("Transaction", { | ||
/** | ||
* A Move Call - any public Move function can be called via | ||
* this transaction. The results can be used that instant to pass | ||
* into the next transaction. | ||
*/ | ||
MoveCall: ProgrammableMoveCall, | ||
/** | ||
* Transfer vector of objects to a receiver. | ||
*/ | ||
TransferObjects: import_bcs2.bcs.struct("TransferObjects", { | ||
objects: import_bcs2.bcs.vector(Argument), | ||
address: Argument | ||
}), | ||
/** | ||
* Split `amount` from a `coin`. | ||
*/ | ||
SplitCoins: import_bcs2.bcs.struct("SplitCoins", { | ||
coin: Argument, | ||
amounts: import_bcs2.bcs.vector(Argument) | ||
}), | ||
/** | ||
* Merge Vector of Coins (`sources`) into a `destination`. | ||
*/ | ||
MergeCoins: import_bcs2.bcs.struct("MergeCoins", { | ||
destination: Argument, | ||
sources: import_bcs2.bcs.vector(Argument) | ||
}), | ||
/** | ||
* Publish a Move module. | ||
*/ | ||
Publish: import_bcs2.bcs.struct("Publish", { | ||
modules: import_bcs2.bcs.vector(import_bcs2.bcs.vector(import_bcs2.bcs.u8())), | ||
dependencies: import_bcs2.bcs.vector(Address) | ||
}), | ||
/** | ||
* Build a vector of objects using the input arguments. | ||
* It is impossible to construct a `vector<T: key>` otherwise, | ||
* so this call serves a utility function. | ||
*/ | ||
MakeMoveVec: import_bcs2.bcs.struct("MakeMoveVec", { | ||
type: optionEnum(TypeTag), | ||
objects: import_bcs2.bcs.vector(Argument) | ||
}), | ||
/** */ | ||
Upgrade: import_bcs2.bcs.struct("Upgrade", { | ||
modules: import_bcs2.bcs.vector(import_bcs2.bcs.vector(import_bcs2.bcs.u8())), | ||
dependencies: import_bcs2.bcs.vector(Address), | ||
packageId: Address, | ||
ticket: Argument | ||
}) | ||
}) | ||
); | ||
var ProgrammableTransaction = import_bcs2.bcs.struct("ProgrammableTransaction", { | ||
inputs: import_bcs2.bcs.vector(CallArg), | ||
transactions: import_bcs2.bcs.vector(Transaction) | ||
}); | ||
var TransactionKind = import_bcs2.bcs.enum("TransactionKind", { | ||
ProgrammableTransaction, | ||
ChangeEpoch: null, | ||
Genesis: null, | ||
ConsensusCommitPrologue: null | ||
}); | ||
var TransactionExpiration = import_bcs2.bcs.enum("TransactionExpiration", { | ||
None: null, | ||
Epoch: unsafe_u64() | ||
}); | ||
var StructTag = import_bcs2.bcs.struct("StructTag", { | ||
address: Address, | ||
module: import_bcs2.bcs.string(), | ||
name: import_bcs2.bcs.string(), | ||
typeParams: import_bcs2.bcs.vector(TypeTag) | ||
}); | ||
var GasData = import_bcs2.bcs.struct("GasData", { | ||
payment: import_bcs2.bcs.vector(SuiObjectRef), | ||
owner: Address, | ||
price: import_bcs2.bcs.u64(), | ||
budget: import_bcs2.bcs.u64() | ||
}); | ||
var TransactionDataV1 = import_bcs2.bcs.struct("TransactionDataV1", { | ||
kind: TransactionKind, | ||
sender: Address, | ||
gasData: GasData, | ||
expiration: TransactionExpiration | ||
}); | ||
var TransactionData = import_bcs2.bcs.enum("TransactionData", { | ||
V1: TransactionDataV1 | ||
}); | ||
var SenderSignedData = import_bcs2.bcs.struct("SenderSignedData", { | ||
data: TransactionData, | ||
txSignatures: import_bcs2.bcs.vector(import_bcs2.bcs.vector(import_bcs2.bcs.u8())) | ||
}); | ||
var CompressedSignature = import_bcs2.bcs.enum("CompressedSignature", { | ||
ED25519: import_bcs2.bcs.fixedArray(64, import_bcs2.bcs.u8()), | ||
Secp256k1: import_bcs2.bcs.fixedArray(64, import_bcs2.bcs.u8()), | ||
Secp256r1: import_bcs2.bcs.fixedArray(64, import_bcs2.bcs.u8()) | ||
}); | ||
var PublicKey = import_bcs2.bcs.enum("PublicKey", { | ||
ED25519: import_bcs2.bcs.fixedArray(32, import_bcs2.bcs.u8()), | ||
Secp256k1: import_bcs2.bcs.fixedArray(33, import_bcs2.bcs.u8()), | ||
Secp256r1: import_bcs2.bcs.fixedArray(33, import_bcs2.bcs.u8()) | ||
}); | ||
var MultiSigPkMap = import_bcs2.bcs.struct("MultiSigPkMap", { | ||
pubKey: PublicKey, | ||
weight: import_bcs2.bcs.u8() | ||
}); | ||
var MultiSigPublicKey = import_bcs2.bcs.struct("MultiSigPublicKey", { | ||
pk_map: import_bcs2.bcs.vector(MultiSigPkMap), | ||
threshold: import_bcs2.bcs.u16() | ||
}); | ||
var MultiSig = import_bcs2.bcs.struct("MultiSig", { | ||
sigs: import_bcs2.bcs.vector(CompressedSignature), | ||
bitmap: import_bcs2.bcs.u16(), | ||
multisig_pk: MultiSigPublicKey | ||
}); | ||
var suiBcs = { | ||
...import_bcs2.bcs, | ||
U8: import_bcs2.bcs.u8(), | ||
U16: import_bcs2.bcs.u16(), | ||
U32: import_bcs2.bcs.u32(), | ||
U64: import_bcs2.bcs.u64(), | ||
U128: import_bcs2.bcs.u128(), | ||
U256: import_bcs2.bcs.u256(), | ||
ULEB128: import_bcs2.bcs.uleb128(), | ||
Bool: import_bcs2.bcs.bool(), | ||
String: import_bcs2.bcs.string(), | ||
Address, | ||
Argument, | ||
CallArg, | ||
CompressedSignature, | ||
GasData, | ||
MultiSig, | ||
MultiSigPkMap, | ||
MultiSigPublicKey, | ||
ObjectArg, | ||
ObjectDigest, | ||
ProgrammableMoveCall, | ||
ProgrammableTransaction, | ||
PublicKey, | ||
SenderSignedData, | ||
SharedObjectRef, | ||
StructTag, | ||
SuiObjectRef, | ||
Transaction, | ||
TransactionData, | ||
TransactionDataV1, | ||
TransactionExpiration, | ||
TransactionKind, | ||
TypeTag, | ||
// preserve backwards compatibility with old bcs export | ||
ser: bcsRegistry.ser.bind(bcsRegistry), | ||
de: bcsRegistry.de.bind(bcsRegistry), | ||
getTypeInterface: bcsRegistry.getTypeInterface.bind(bcsRegistry), | ||
hasType: bcsRegistry.hasType.bind(bcsRegistry), | ||
parseTypeName: bcsRegistry.parseTypeName.bind(bcsRegistry), | ||
registerAddressType: bcsRegistry.registerAddressType.bind(bcsRegistry), | ||
registerAlias: bcsRegistry.registerAlias.bind(bcsRegistry), | ||
registerBcsType: bcsRegistry.registerBcsType.bind(bcsRegistry), | ||
registerEnumType: bcsRegistry.registerEnumType.bind(bcsRegistry), | ||
registerStructType: bcsRegistry.registerStructType.bind(bcsRegistry), | ||
registerType: bcsRegistry.registerType.bind(bcsRegistry), | ||
types: bcsRegistry.types | ||
}; | ||
bcsRegistry.registerBcsType( | ||
"utf8string", | ||
() => import_bcs2.bcs.string({ name: "utf8string" }) | ||
); | ||
bcsRegistry.registerBcsType("unsafe_u64", () => unsafe_u64()); | ||
bcsRegistry.registerBcsType("enumKind", (T) => enumKind(T)); | ||
[ | ||
Address, | ||
Argument, | ||
CallArg, | ||
CompressedSignature, | ||
GasData, | ||
MultiSig, | ||
MultiSigPkMap, | ||
MultiSigPublicKey, | ||
ObjectArg, | ||
ObjectDigest, | ||
ProgrammableMoveCall, | ||
ProgrammableTransaction, | ||
PublicKey, | ||
SenderSignedData, | ||
SharedObjectRef, | ||
StructTag, | ||
SuiObjectRef, | ||
Transaction, | ||
TransactionData, | ||
TransactionDataV1, | ||
TransactionExpiration, | ||
TransactionKind, | ||
TypeTag | ||
].forEach((type) => { | ||
bcsRegistry.registerBcsType(type.name, () => type); | ||
}); | ||
// src/libs/multiSig/multiSig.ts | ||
function toMultiSigAddress(pks, threshold) { | ||
if (pks.length > import_multisig.MAX_SIGNER_IN_MULTISIG) { | ||
throw new Error( | ||
`Max number of signers in a multisig is ${import_multisig.MAX_SIGNER_IN_MULTISIG}` | ||
); | ||
} | ||
if (pks.length < import_multisig.MIN_SIGNER_IN_MULTISIG) { | ||
throw new Error( | ||
`Min number of signers in a multisig is ${import_multisig.MIN_SIGNER_IN_MULTISIG}` | ||
); | ||
} | ||
const maxLength = 1 + 2 + pks.length * (1 + 64 + 1); | ||
const buf = new Uint8Array(maxLength); | ||
let offset = 0; | ||
buf.set([import_cryptography.SIGNATURE_SCHEME_TO_FLAG.MultiSig], offset); | ||
offset += 1; | ||
buf.set([threshold & 255, threshold >> 8], offset); | ||
offset += 2; | ||
let totalWeight = 0; | ||
for (let i = 0; i < pks.length; i++) { | ||
const { pubKey, weight } = pks[i]; | ||
const flag = pubKey.flag(); | ||
buf.set([flag], offset); | ||
offset += 1; | ||
buf.set(pubKey.toRawBytes(), offset); | ||
offset += pubKey.toRawBytes().length; | ||
buf.set([weight], offset); | ||
offset += 1; | ||
totalWeight += weight; | ||
} | ||
if (totalWeight < threshold) { | ||
throw new Error(`Total weight is less than threshold`); | ||
} | ||
const bufHash = (0, import_blake2b.blake2b)(buf.slice(0, offset), { dkLen: 32 }); | ||
return (0, import_utils7.normalizeSuiAddress)((0, import_utils6.bytesToHex)(bufHash)); | ||
} | ||
function combinePartialSigs(sigs, pks, threshold) { | ||
if (sigs.length > import_multisig.MAX_SIGNER_IN_MULTISIG) { | ||
throw new Error( | ||
`Max number of signers in a multisig is ${import_multisig.MAX_SIGNER_IN_MULTISIG}` | ||
); | ||
} | ||
const multiSigPk = { | ||
pk_map: pks.map((pk) => toPkEnumWeightPair(pk)), | ||
threshold | ||
}; | ||
let bitmap = 0; | ||
const compressedSigs = new Array(sigs.length); | ||
for (let i = 0; i < sigs.length; i++) { | ||
const parsed = toSingleSignaturePubkeyPair(sigs[i]); | ||
const bytes2 = Array.from(parsed.signature.map((x) => Number(x))); | ||
if (parsed.signatureScheme === "ED25519") { | ||
compressedSigs[i] = { ED25519: bytes2 }; | ||
} else if (parsed.signatureScheme === "Secp256k1") { | ||
compressedSigs[i] = { Secp256k1: bytes2 }; | ||
} else if (parsed.signatureScheme === "Secp256r1") { | ||
compressedSigs[i] = { Secp256r1: bytes2 }; | ||
} | ||
for (let j = 0; j < pks.length; j++) { | ||
if (parsed.pubKey.equals(pks[j].pubKey)) { | ||
bitmap |= 1 << j; | ||
break; | ||
} | ||
} | ||
} | ||
const multiSig = { | ||
sigs: compressedSigs, | ||
bitmap, | ||
multisig_pk: multiSigPk | ||
}; | ||
const bytes = suiBcs.MultiSig.serialize(multiSig).toBytes(); | ||
const tmp = new Uint8Array(bytes.length + 1); | ||
tmp.set([import_cryptography.SIGNATURE_SCHEME_TO_FLAG.MultiSig], 0); | ||
tmp.set(bytes, 1); | ||
return (0, import_utils7.toB64)(tmp); | ||
} | ||
function toPkEnumWeightPair(pair) { | ||
const pk_bytes = Array.from(pair.pubKey.toBytes().map((x) => Number(x))); | ||
switch (pair.pubKey.flag()) { | ||
case import_cryptography.SIGNATURE_SCHEME_TO_FLAG["Secp256k1"]: | ||
return { | ||
pubKey: { | ||
Secp256k1: pk_bytes | ||
}, | ||
weight: pair.weight | ||
}; | ||
case import_cryptography.SIGNATURE_SCHEME_TO_FLAG["Secp256r1"]: | ||
return { | ||
pubKey: { | ||
Secp256r1: pk_bytes | ||
}, | ||
weight: pair.weight | ||
}; | ||
case import_cryptography.SIGNATURE_SCHEME_TO_FLAG["ED25519"]: | ||
return { | ||
pubKey: { | ||
ED25519: pk_bytes | ||
}, | ||
weight: pair.weight | ||
}; | ||
default: | ||
throw new Error("Unsupported signature scheme"); | ||
} | ||
} | ||
function toSingleSignaturePubkeyPair(serializedSignature) { | ||
const res = toParsedSignaturePubkeyPair(serializedSignature); | ||
if (res.length !== 1) { | ||
throw Error("Expected a single signature"); | ||
} | ||
return res[0]; | ||
} | ||
function toParsedSignaturePubkeyPair(serializedSignature) { | ||
const bytes = (0, import_utils7.fromB64)(serializedSignature); | ||
const signatureScheme = import_cryptography.SIGNATURE_FLAG_TO_SCHEME[bytes[0]]; | ||
if (signatureScheme === "Zk") { | ||
throw new Error("Zk signature not supported"); | ||
} | ||
if (signatureScheme === "MultiSig") { | ||
throw new Error("MultiSig signature not supported"); | ||
} | ||
const SIGNATURE_SCHEME_TO_PUBLIC_KEY = { | ||
ED25519: import_ed255193.Ed25519PublicKey, | ||
Secp256k1: import_secp256k1.Secp256k1PublicKey, | ||
Secp256r1: import_secp256r1.Secp256r1PublicKey | ||
}; | ||
const PublicKey3 = SIGNATURE_SCHEME_TO_PUBLIC_KEY[signatureScheme]; | ||
const signature = bytes.slice(1, bytes.length - PublicKey3.SIZE); | ||
const pubKeyBytes = bytes.slice(1 + signature.length); | ||
const pubKey = new PublicKey3(pubKeyBytes); | ||
return [ | ||
{ | ||
signatureScheme, | ||
signature, | ||
pubKey | ||
} | ||
]; | ||
} | ||
// src/libs/multiSig/publickey.ts | ||
var import_ed255194 = require("@mysten/sui.js/keypairs/ed25519"); | ||
var import_utils8 = require("@mysten/sui.js/utils"); | ||
function ed25519PublicKeyFromBase64(rawPubkey) { | ||
let bytes = (0, import_utils8.fromB64)(rawPubkey); | ||
if (bytes.length !== 32 && bytes.length !== 33) | ||
throw "invalid pubkey length"; | ||
bytes = bytes.length === 33 ? bytes.slice(1) : bytes; | ||
return new import_ed255194.Ed25519PublicKey(bytes); | ||
} | ||
// src/libs/multiSig/client.ts | ||
var MultiSigClient = class _MultiSigClient { | ||
constructor(pks, threshold) { | ||
this.pksWeightPairs = pks; | ||
this.threshold = threshold; | ||
} | ||
static fromRawPubkeys(rawPubkeys, weights, threshold) { | ||
const pks = rawPubkeys.map((rawPubkey, i) => { | ||
return { | ||
pubKey: ed25519PublicKeyFromBase64(rawPubkey), | ||
weight: weights[i] | ||
}; | ||
}); | ||
return new _MultiSigClient(pks, threshold); | ||
} | ||
multiSigAddress() { | ||
return toMultiSigAddress(this.pksWeightPairs, this.threshold); | ||
} | ||
combinePartialSigs(sigs) { | ||
return combinePartialSigs(sigs, this.pksWeightPairs, this.threshold); | ||
} | ||
}; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
MultiSigClient, | ||
SuiAccountManager, | ||
@@ -792,0 +1389,0 @@ SuiKit, |
@@ -6,2 +6,3 @@ export * from '@mysten/sui.js/utils'; | ||
export { SuiTxBlock } from './libs/suiTxBuilder'; | ||
export { MultiSigClient } from './libs/multiSig'; | ||
export type * from './types'; |
@@ -24,2 +24,3 @@ "use strict"; | ||
__export(src_exports, { | ||
MultiSigClient: () => MultiSigClient, | ||
SuiAccountManager: () => SuiAccountManager, | ||
@@ -788,4 +789,600 @@ SuiKit: () => SuiKit, | ||
}; | ||
// src/libs/multiSig/multiSig.ts | ||
var import_blake2b = require("@noble/hashes/blake2b"); | ||
var import_utils6 = require("@noble/hashes/utils"); | ||
var import_ed255193 = require("@mysten/sui.js/keypairs/ed25519"); | ||
var import_secp256r1 = require("@mysten/sui.js/keypairs/secp256r1"); | ||
var import_secp256k1 = require("@mysten/sui.js/keypairs/secp256k1"); | ||
var import_multisig = require("@mysten/sui.js/multisig"); | ||
var import_utils7 = require("@mysten/sui.js/utils"); | ||
var import_cryptography = require("@mysten/sui.js/cryptography"); | ||
// src/libs/bcs/bcs.ts | ||
var import_bcs2 = require("@mysten/bcs"); | ||
var import_utils5 = require("@mysten/sui.js/utils"); | ||
// src/libs/bcs/typeTagSerializer.ts | ||
var import_bcs = require("@mysten/bcs"); | ||
var import_utils4 = require("@mysten/sui.js/utils"); | ||
var VECTOR_REGEX = /^vector<(.+)>$/; | ||
var STRUCT_REGEX = /^([^:]+)::([^:]+)::([^<]+)(<(.+)>)?/; | ||
var TypeTagSerializer = class _TypeTagSerializer { | ||
static parseFromStr(str, normalizeAddress = false) { | ||
if (str === "address") { | ||
return { address: null }; | ||
} else if (str === "bool") { | ||
return { bool: null }; | ||
} else if (str === "u8") { | ||
return { u8: null }; | ||
} else if (str === "u16") { | ||
return { u16: null }; | ||
} else if (str === "u32") { | ||
return { u32: null }; | ||
} else if (str === "u64") { | ||
return { u64: null }; | ||
} else if (str === "u128") { | ||
return { u128: null }; | ||
} else if (str === "u256") { | ||
return { u256: null }; | ||
} else if (str === "signer") { | ||
return { signer: null }; | ||
} | ||
const vectorMatch = str.match(VECTOR_REGEX); | ||
if (vectorMatch) { | ||
return { | ||
vector: _TypeTagSerializer.parseFromStr( | ||
vectorMatch[1], | ||
normalizeAddress | ||
) | ||
}; | ||
} | ||
const structMatch = str.match(STRUCT_REGEX); | ||
if (structMatch) { | ||
const address = normalizeAddress ? (0, import_utils4.normalizeSuiAddress)(structMatch[1]) : structMatch[1]; | ||
return { | ||
struct: { | ||
address, | ||
module: structMatch[2], | ||
name: structMatch[3], | ||
typeParams: structMatch[5] === void 0 ? [] : _TypeTagSerializer.parseStructTypeArgs( | ||
structMatch[5], | ||
normalizeAddress | ||
) | ||
} | ||
}; | ||
} | ||
throw new Error( | ||
`Encountered unexpected token when parsing type args for ${str}` | ||
); | ||
} | ||
static parseStructTypeArgs(str, normalizeAddress = false) { | ||
return (0, import_bcs.splitGenericParameters)(str).map( | ||
(tok) => _TypeTagSerializer.parseFromStr(tok, normalizeAddress) | ||
); | ||
} | ||
static tagToString(tag) { | ||
if ("bool" in tag) { | ||
return "bool"; | ||
} | ||
if ("u8" in tag) { | ||
return "u8"; | ||
} | ||
if ("u16" in tag) { | ||
return "u16"; | ||
} | ||
if ("u32" in tag) { | ||
return "u32"; | ||
} | ||
if ("u64" in tag) { | ||
return "u64"; | ||
} | ||
if ("u128" in tag) { | ||
return "u128"; | ||
} | ||
if ("u256" in tag) { | ||
return "u256"; | ||
} | ||
if ("address" in tag) { | ||
return "address"; | ||
} | ||
if ("signer" in tag) { | ||
return "signer"; | ||
} | ||
if ("vector" in tag) { | ||
return `vector<${_TypeTagSerializer.tagToString(tag.vector)}>`; | ||
} | ||
if ("struct" in tag) { | ||
const struct = tag.struct; | ||
const typeParams = struct.typeParams.map(_TypeTagSerializer.tagToString).join(", "); | ||
return `${struct.address}::${struct.module}::${struct.name}${typeParams ? `<${typeParams}>` : ""}`; | ||
} | ||
throw new Error("Invalid TypeTag"); | ||
} | ||
}; | ||
// src/libs/bcs/bcs.ts | ||
var bcsRegistry = new import_bcs2.BCS({ ...(0, import_bcs2.getSuiMoveConfig)() }); | ||
function unsafe_u64(options) { | ||
return import_bcs2.bcs.u64({ | ||
name: "unsafe_u64", | ||
...options | ||
}).transform({ | ||
input: (val) => val, | ||
output: (val) => Number(val) | ||
}); | ||
} | ||
function optionEnum(type) { | ||
return import_bcs2.bcs.enum("Option", { | ||
None: null, | ||
Some: type | ||
}); | ||
} | ||
function enumKind(type) { | ||
return type.transform({ | ||
input: (val) => ({ | ||
[val.kind]: val | ||
}), | ||
output: (val) => { | ||
const key = Object.keys(val)[0]; | ||
return { kind: key, ...val[key] }; | ||
} | ||
}); | ||
} | ||
var Address = import_bcs2.bcs.bytes(import_utils5.SUI_ADDRESS_LENGTH).transform({ | ||
input: (val) => typeof val === "string" ? (0, import_bcs2.fromHEX)(val) : val, | ||
output: (val) => (0, import_bcs2.toHEX)(val) | ||
}); | ||
var ObjectDigest = import_bcs2.bcs.vector(import_bcs2.bcs.u8()).transform({ | ||
name: "ObjectDigest", | ||
input: (value) => (0, import_bcs2.fromB58)(value), | ||
output: (value) => (0, import_bcs2.toB58)(new Uint8Array(value)) | ||
}); | ||
var SuiObjectRef = import_bcs2.bcs.struct("SuiObjectRef", { | ||
objectId: Address, | ||
version: import_bcs2.bcs.u64(), | ||
digest: ObjectDigest | ||
}); | ||
var SharedObjectRef = import_bcs2.bcs.struct("SharedObjectRef", { | ||
objectId: Address, | ||
initialSharedVersion: import_bcs2.bcs.u64(), | ||
mutable: import_bcs2.bcs.bool() | ||
}); | ||
var ObjectArg = import_bcs2.bcs.enum("ObjectArg", { | ||
ImmOrOwned: SuiObjectRef, | ||
Shared: SharedObjectRef | ||
}); | ||
var CallArg = import_bcs2.bcs.enum("CallArg", { | ||
Pure: import_bcs2.bcs.vector(import_bcs2.bcs.u8()), | ||
Object: ObjectArg, | ||
ObjVec: import_bcs2.bcs.vector(ObjectArg) | ||
}); | ||
var TypeTag = import_bcs2.bcs.enum("TypeTag", { | ||
bool: null, | ||
u8: null, | ||
u64: null, | ||
u128: null, | ||
address: null, | ||
signer: null, | ||
vector: import_bcs2.bcs.lazy(() => TypeTag), | ||
struct: import_bcs2.bcs.lazy(() => StructTag), | ||
u16: null, | ||
u32: null, | ||
u256: null | ||
}); | ||
var Argument = enumKind( | ||
import_bcs2.bcs.enum("Argument", { | ||
GasCoin: null, | ||
Input: import_bcs2.bcs.struct("Input", { index: import_bcs2.bcs.u16() }), | ||
Result: import_bcs2.bcs.struct("Result", { index: import_bcs2.bcs.u16() }), | ||
NestedResult: import_bcs2.bcs.struct("NestedResult", { | ||
index: import_bcs2.bcs.u16(), | ||
resultIndex: import_bcs2.bcs.u16() | ||
}) | ||
}) | ||
); | ||
var ProgrammableMoveCall = import_bcs2.bcs.struct("ProgrammableMoveCall", { | ||
package: Address, | ||
module: import_bcs2.bcs.string(), | ||
function: import_bcs2.bcs.string(), | ||
type_arguments: import_bcs2.bcs.vector(TypeTag), | ||
arguments: import_bcs2.bcs.vector(Argument) | ||
}).transform({ | ||
// TODO: add type for the input data | ||
input: (data) => { | ||
const [pkg, module2, fun] = data.target.split("::"); | ||
const type_arguments = data.typeArguments.map( | ||
(tag) => TypeTagSerializer.parseFromStr(tag, true) | ||
); | ||
return { | ||
package: (0, import_utils5.normalizeSuiAddress)(pkg), | ||
module: module2, | ||
function: fun, | ||
type_arguments, | ||
arguments: data.arguments | ||
}; | ||
}, | ||
output: (data) => { | ||
return { | ||
target: [data.package, data.module, data.function].join( | ||
"::" | ||
), | ||
arguments: data.arguments, | ||
typeArguments: data.type_arguments.map(TypeTagSerializer.tagToString) | ||
}; | ||
} | ||
}); | ||
var Transaction = enumKind( | ||
import_bcs2.bcs.enum("Transaction", { | ||
/** | ||
* A Move Call - any public Move function can be called via | ||
* this transaction. The results can be used that instant to pass | ||
* into the next transaction. | ||
*/ | ||
MoveCall: ProgrammableMoveCall, | ||
/** | ||
* Transfer vector of objects to a receiver. | ||
*/ | ||
TransferObjects: import_bcs2.bcs.struct("TransferObjects", { | ||
objects: import_bcs2.bcs.vector(Argument), | ||
address: Argument | ||
}), | ||
/** | ||
* Split `amount` from a `coin`. | ||
*/ | ||
SplitCoins: import_bcs2.bcs.struct("SplitCoins", { | ||
coin: Argument, | ||
amounts: import_bcs2.bcs.vector(Argument) | ||
}), | ||
/** | ||
* Merge Vector of Coins (`sources`) into a `destination`. | ||
*/ | ||
MergeCoins: import_bcs2.bcs.struct("MergeCoins", { | ||
destination: Argument, | ||
sources: import_bcs2.bcs.vector(Argument) | ||
}), | ||
/** | ||
* Publish a Move module. | ||
*/ | ||
Publish: import_bcs2.bcs.struct("Publish", { | ||
modules: import_bcs2.bcs.vector(import_bcs2.bcs.vector(import_bcs2.bcs.u8())), | ||
dependencies: import_bcs2.bcs.vector(Address) | ||
}), | ||
/** | ||
* Build a vector of objects using the input arguments. | ||
* It is impossible to construct a `vector<T: key>` otherwise, | ||
* so this call serves a utility function. | ||
*/ | ||
MakeMoveVec: import_bcs2.bcs.struct("MakeMoveVec", { | ||
type: optionEnum(TypeTag), | ||
objects: import_bcs2.bcs.vector(Argument) | ||
}), | ||
/** */ | ||
Upgrade: import_bcs2.bcs.struct("Upgrade", { | ||
modules: import_bcs2.bcs.vector(import_bcs2.bcs.vector(import_bcs2.bcs.u8())), | ||
dependencies: import_bcs2.bcs.vector(Address), | ||
packageId: Address, | ||
ticket: Argument | ||
}) | ||
}) | ||
); | ||
var ProgrammableTransaction = import_bcs2.bcs.struct("ProgrammableTransaction", { | ||
inputs: import_bcs2.bcs.vector(CallArg), | ||
transactions: import_bcs2.bcs.vector(Transaction) | ||
}); | ||
var TransactionKind = import_bcs2.bcs.enum("TransactionKind", { | ||
ProgrammableTransaction, | ||
ChangeEpoch: null, | ||
Genesis: null, | ||
ConsensusCommitPrologue: null | ||
}); | ||
var TransactionExpiration = import_bcs2.bcs.enum("TransactionExpiration", { | ||
None: null, | ||
Epoch: unsafe_u64() | ||
}); | ||
var StructTag = import_bcs2.bcs.struct("StructTag", { | ||
address: Address, | ||
module: import_bcs2.bcs.string(), | ||
name: import_bcs2.bcs.string(), | ||
typeParams: import_bcs2.bcs.vector(TypeTag) | ||
}); | ||
var GasData = import_bcs2.bcs.struct("GasData", { | ||
payment: import_bcs2.bcs.vector(SuiObjectRef), | ||
owner: Address, | ||
price: import_bcs2.bcs.u64(), | ||
budget: import_bcs2.bcs.u64() | ||
}); | ||
var TransactionDataV1 = import_bcs2.bcs.struct("TransactionDataV1", { | ||
kind: TransactionKind, | ||
sender: Address, | ||
gasData: GasData, | ||
expiration: TransactionExpiration | ||
}); | ||
var TransactionData = import_bcs2.bcs.enum("TransactionData", { | ||
V1: TransactionDataV1 | ||
}); | ||
var SenderSignedData = import_bcs2.bcs.struct("SenderSignedData", { | ||
data: TransactionData, | ||
txSignatures: import_bcs2.bcs.vector(import_bcs2.bcs.vector(import_bcs2.bcs.u8())) | ||
}); | ||
var CompressedSignature = import_bcs2.bcs.enum("CompressedSignature", { | ||
ED25519: import_bcs2.bcs.fixedArray(64, import_bcs2.bcs.u8()), | ||
Secp256k1: import_bcs2.bcs.fixedArray(64, import_bcs2.bcs.u8()), | ||
Secp256r1: import_bcs2.bcs.fixedArray(64, import_bcs2.bcs.u8()) | ||
}); | ||
var PublicKey = import_bcs2.bcs.enum("PublicKey", { | ||
ED25519: import_bcs2.bcs.fixedArray(32, import_bcs2.bcs.u8()), | ||
Secp256k1: import_bcs2.bcs.fixedArray(33, import_bcs2.bcs.u8()), | ||
Secp256r1: import_bcs2.bcs.fixedArray(33, import_bcs2.bcs.u8()) | ||
}); | ||
var MultiSigPkMap = import_bcs2.bcs.struct("MultiSigPkMap", { | ||
pubKey: PublicKey, | ||
weight: import_bcs2.bcs.u8() | ||
}); | ||
var MultiSigPublicKey = import_bcs2.bcs.struct("MultiSigPublicKey", { | ||
pk_map: import_bcs2.bcs.vector(MultiSigPkMap), | ||
threshold: import_bcs2.bcs.u16() | ||
}); | ||
var MultiSig = import_bcs2.bcs.struct("MultiSig", { | ||
sigs: import_bcs2.bcs.vector(CompressedSignature), | ||
bitmap: import_bcs2.bcs.u16(), | ||
multisig_pk: MultiSigPublicKey | ||
}); | ||
var suiBcs = { | ||
...import_bcs2.bcs, | ||
U8: import_bcs2.bcs.u8(), | ||
U16: import_bcs2.bcs.u16(), | ||
U32: import_bcs2.bcs.u32(), | ||
U64: import_bcs2.bcs.u64(), | ||
U128: import_bcs2.bcs.u128(), | ||
U256: import_bcs2.bcs.u256(), | ||
ULEB128: import_bcs2.bcs.uleb128(), | ||
Bool: import_bcs2.bcs.bool(), | ||
String: import_bcs2.bcs.string(), | ||
Address, | ||
Argument, | ||
CallArg, | ||
CompressedSignature, | ||
GasData, | ||
MultiSig, | ||
MultiSigPkMap, | ||
MultiSigPublicKey, | ||
ObjectArg, | ||
ObjectDigest, | ||
ProgrammableMoveCall, | ||
ProgrammableTransaction, | ||
PublicKey, | ||
SenderSignedData, | ||
SharedObjectRef, | ||
StructTag, | ||
SuiObjectRef, | ||
Transaction, | ||
TransactionData, | ||
TransactionDataV1, | ||
TransactionExpiration, | ||
TransactionKind, | ||
TypeTag, | ||
// preserve backwards compatibility with old bcs export | ||
ser: bcsRegistry.ser.bind(bcsRegistry), | ||
de: bcsRegistry.de.bind(bcsRegistry), | ||
getTypeInterface: bcsRegistry.getTypeInterface.bind(bcsRegistry), | ||
hasType: bcsRegistry.hasType.bind(bcsRegistry), | ||
parseTypeName: bcsRegistry.parseTypeName.bind(bcsRegistry), | ||
registerAddressType: bcsRegistry.registerAddressType.bind(bcsRegistry), | ||
registerAlias: bcsRegistry.registerAlias.bind(bcsRegistry), | ||
registerBcsType: bcsRegistry.registerBcsType.bind(bcsRegistry), | ||
registerEnumType: bcsRegistry.registerEnumType.bind(bcsRegistry), | ||
registerStructType: bcsRegistry.registerStructType.bind(bcsRegistry), | ||
registerType: bcsRegistry.registerType.bind(bcsRegistry), | ||
types: bcsRegistry.types | ||
}; | ||
bcsRegistry.registerBcsType( | ||
"utf8string", | ||
() => import_bcs2.bcs.string({ name: "utf8string" }) | ||
); | ||
bcsRegistry.registerBcsType("unsafe_u64", () => unsafe_u64()); | ||
bcsRegistry.registerBcsType("enumKind", (T) => enumKind(T)); | ||
[ | ||
Address, | ||
Argument, | ||
CallArg, | ||
CompressedSignature, | ||
GasData, | ||
MultiSig, | ||
MultiSigPkMap, | ||
MultiSigPublicKey, | ||
ObjectArg, | ||
ObjectDigest, | ||
ProgrammableMoveCall, | ||
ProgrammableTransaction, | ||
PublicKey, | ||
SenderSignedData, | ||
SharedObjectRef, | ||
StructTag, | ||
SuiObjectRef, | ||
Transaction, | ||
TransactionData, | ||
TransactionDataV1, | ||
TransactionExpiration, | ||
TransactionKind, | ||
TypeTag | ||
].forEach((type) => { | ||
bcsRegistry.registerBcsType(type.name, () => type); | ||
}); | ||
// src/libs/multiSig/multiSig.ts | ||
function toMultiSigAddress(pks, threshold) { | ||
if (pks.length > import_multisig.MAX_SIGNER_IN_MULTISIG) { | ||
throw new Error( | ||
`Max number of signers in a multisig is ${import_multisig.MAX_SIGNER_IN_MULTISIG}` | ||
); | ||
} | ||
if (pks.length < import_multisig.MIN_SIGNER_IN_MULTISIG) { | ||
throw new Error( | ||
`Min number of signers in a multisig is ${import_multisig.MIN_SIGNER_IN_MULTISIG}` | ||
); | ||
} | ||
const maxLength = 1 + 2 + pks.length * (1 + 64 + 1); | ||
const buf = new Uint8Array(maxLength); | ||
let offset = 0; | ||
buf.set([import_cryptography.SIGNATURE_SCHEME_TO_FLAG.MultiSig], offset); | ||
offset += 1; | ||
buf.set([threshold & 255, threshold >> 8], offset); | ||
offset += 2; | ||
let totalWeight = 0; | ||
for (let i = 0; i < pks.length; i++) { | ||
const { pubKey, weight } = pks[i]; | ||
const flag = pubKey.flag(); | ||
buf.set([flag], offset); | ||
offset += 1; | ||
buf.set(pubKey.toRawBytes(), offset); | ||
offset += pubKey.toRawBytes().length; | ||
buf.set([weight], offset); | ||
offset += 1; | ||
totalWeight += weight; | ||
} | ||
if (totalWeight < threshold) { | ||
throw new Error(`Total weight is less than threshold`); | ||
} | ||
const bufHash = (0, import_blake2b.blake2b)(buf.slice(0, offset), { dkLen: 32 }); | ||
return (0, import_utils7.normalizeSuiAddress)((0, import_utils6.bytesToHex)(bufHash)); | ||
} | ||
function combinePartialSigs(sigs, pks, threshold) { | ||
if (sigs.length > import_multisig.MAX_SIGNER_IN_MULTISIG) { | ||
throw new Error( | ||
`Max number of signers in a multisig is ${import_multisig.MAX_SIGNER_IN_MULTISIG}` | ||
); | ||
} | ||
const multiSigPk = { | ||
pk_map: pks.map((pk) => toPkEnumWeightPair(pk)), | ||
threshold | ||
}; | ||
let bitmap = 0; | ||
const compressedSigs = new Array(sigs.length); | ||
for (let i = 0; i < sigs.length; i++) { | ||
const parsed = toSingleSignaturePubkeyPair(sigs[i]); | ||
const bytes2 = Array.from(parsed.signature.map((x) => Number(x))); | ||
if (parsed.signatureScheme === "ED25519") { | ||
compressedSigs[i] = { ED25519: bytes2 }; | ||
} else if (parsed.signatureScheme === "Secp256k1") { | ||
compressedSigs[i] = { Secp256k1: bytes2 }; | ||
} else if (parsed.signatureScheme === "Secp256r1") { | ||
compressedSigs[i] = { Secp256r1: bytes2 }; | ||
} | ||
for (let j = 0; j < pks.length; j++) { | ||
if (parsed.pubKey.equals(pks[j].pubKey)) { | ||
bitmap |= 1 << j; | ||
break; | ||
} | ||
} | ||
} | ||
const multiSig = { | ||
sigs: compressedSigs, | ||
bitmap, | ||
multisig_pk: multiSigPk | ||
}; | ||
const bytes = suiBcs.MultiSig.serialize(multiSig).toBytes(); | ||
const tmp = new Uint8Array(bytes.length + 1); | ||
tmp.set([import_cryptography.SIGNATURE_SCHEME_TO_FLAG.MultiSig], 0); | ||
tmp.set(bytes, 1); | ||
return (0, import_utils7.toB64)(tmp); | ||
} | ||
function toPkEnumWeightPair(pair) { | ||
const pk_bytes = Array.from(pair.pubKey.toBytes().map((x) => Number(x))); | ||
switch (pair.pubKey.flag()) { | ||
case import_cryptography.SIGNATURE_SCHEME_TO_FLAG["Secp256k1"]: | ||
return { | ||
pubKey: { | ||
Secp256k1: pk_bytes | ||
}, | ||
weight: pair.weight | ||
}; | ||
case import_cryptography.SIGNATURE_SCHEME_TO_FLAG["Secp256r1"]: | ||
return { | ||
pubKey: { | ||
Secp256r1: pk_bytes | ||
}, | ||
weight: pair.weight | ||
}; | ||
case import_cryptography.SIGNATURE_SCHEME_TO_FLAG["ED25519"]: | ||
return { | ||
pubKey: { | ||
ED25519: pk_bytes | ||
}, | ||
weight: pair.weight | ||
}; | ||
default: | ||
throw new Error("Unsupported signature scheme"); | ||
} | ||
} | ||
function toSingleSignaturePubkeyPair(serializedSignature) { | ||
const res = toParsedSignaturePubkeyPair(serializedSignature); | ||
if (res.length !== 1) { | ||
throw Error("Expected a single signature"); | ||
} | ||
return res[0]; | ||
} | ||
function toParsedSignaturePubkeyPair(serializedSignature) { | ||
const bytes = (0, import_utils7.fromB64)(serializedSignature); | ||
const signatureScheme = import_cryptography.SIGNATURE_FLAG_TO_SCHEME[bytes[0]]; | ||
if (signatureScheme === "Zk") { | ||
throw new Error("Zk signature not supported"); | ||
} | ||
if (signatureScheme === "MultiSig") { | ||
throw new Error("MultiSig signature not supported"); | ||
} | ||
const SIGNATURE_SCHEME_TO_PUBLIC_KEY = { | ||
ED25519: import_ed255193.Ed25519PublicKey, | ||
Secp256k1: import_secp256k1.Secp256k1PublicKey, | ||
Secp256r1: import_secp256r1.Secp256r1PublicKey | ||
}; | ||
const PublicKey3 = SIGNATURE_SCHEME_TO_PUBLIC_KEY[signatureScheme]; | ||
const signature = bytes.slice(1, bytes.length - PublicKey3.SIZE); | ||
const pubKeyBytes = bytes.slice(1 + signature.length); | ||
const pubKey = new PublicKey3(pubKeyBytes); | ||
return [ | ||
{ | ||
signatureScheme, | ||
signature, | ||
pubKey | ||
} | ||
]; | ||
} | ||
// src/libs/multiSig/publickey.ts | ||
var import_ed255194 = require("@mysten/sui.js/keypairs/ed25519"); | ||
var import_utils8 = require("@mysten/sui.js/utils"); | ||
function ed25519PublicKeyFromBase64(rawPubkey) { | ||
let bytes = (0, import_utils8.fromB64)(rawPubkey); | ||
if (bytes.length !== 32 && bytes.length !== 33) | ||
throw "invalid pubkey length"; | ||
bytes = bytes.length === 33 ? bytes.slice(1) : bytes; | ||
return new import_ed255194.Ed25519PublicKey(bytes); | ||
} | ||
// src/libs/multiSig/client.ts | ||
var MultiSigClient = class _MultiSigClient { | ||
constructor(pks, threshold) { | ||
this.pksWeightPairs = pks; | ||
this.threshold = threshold; | ||
} | ||
static fromRawPubkeys(rawPubkeys, weights, threshold) { | ||
const pks = rawPubkeys.map((rawPubkey, i) => { | ||
return { | ||
pubKey: ed25519PublicKeyFromBase64(rawPubkey), | ||
weight: weights[i] | ||
}; | ||
}); | ||
return new _MultiSigClient(pks, threshold); | ||
} | ||
multiSigAddress() { | ||
return toMultiSigAddress(this.pksWeightPairs, this.threshold); | ||
} | ||
combinePartialSigs(sigs) { | ||
return combinePartialSigs(sigs, this.pksWeightPairs, this.threshold); | ||
} | ||
}; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
MultiSigClient, | ||
SuiAccountManager, | ||
@@ -792,0 +1389,0 @@ SuiKit, |
{ | ||
"name": "@scallop-io/sui-kit", | ||
"version": "0.42.0", | ||
"version": "0.42.1", | ||
"description": "Tookit for interacting with SUI network", | ||
@@ -40,3 +40,5 @@ "keywords": [ | ||
"dependencies": { | ||
"@mysten/bcs": "^0.8.0", | ||
"@mysten/sui.js": "^0.42.0", | ||
"@noble/hashes": "^1.3.2", | ||
"@scure/bip39": "^1.2.1", | ||
@@ -43,0 +45,0 @@ "assert": "^2.1.0", |
@@ -6,2 +6,3 @@ export * from '@mysten/sui.js/utils'; | ||
export { SuiTxBlock } from './libs/suiTxBuilder'; | ||
export { MultiSigClient } from './libs/multiSig'; | ||
export type * from './types'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
526592
52
9903
8
+ Added@mysten/bcs@^0.8.0
+ Added@noble/hashes@^1.3.2
+ Added@mysten/bcs@0.8.1(transitive)
+ Added@noble/curves@1.6.0(transitive)
+ Added@noble/hashes@1.5.0(transitive)
+ Added@scure/base@1.1.9(transitive)
+ Added@scure/bip32@1.5.0(transitive)
+ Added@scure/bip39@1.4.0(transitive)
- Removed@noble/curves@1.7.0(transitive)
- Removed@noble/hashes@1.6.01.6.1(transitive)
- Removed@scure/base@1.2.1(transitive)
- Removed@scure/bip32@1.6.0(transitive)
- Removed@scure/bip39@1.5.0(transitive)