@scallop-io/sui-kit 0.42.0 → 0.42.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -3,4 +3,5 @@ export * from '@mysten/sui.js/transactions';
3
3
  export { SuiKit } from './suiKit';
4
4
  export { SuiAccountManager } from './libs/suiAccountManager';
5
5
  export { SuiTxBlock } from './libs/suiTxBuilder';
6
+ export { MultiSigClient } from './libs/multiSig';
6
7
  export type * from './types';
package/dist/index.js CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  // src/index.ts
22
22
  var src_exports = {};
23
23
  __export(src_exports, {
24
+ MultiSigClient: () => MultiSigClient,
24
25
  SuiAccountManager: () => SuiAccountManager,
25
26
  SuiKit: () => SuiKit,
26
27
  SuiTxBlock: () => SuiTxBlock
@@ -784,8 +785,604 @@ var SuiKit = class {
784
785
  });
785
786
  }
786
787
  };
788
+
789
+ // src/libs/multiSig/multiSig.ts
790
+ var import_blake2b = require("@noble/hashes/blake2b");
791
+ var import_utils6 = require("@noble/hashes/utils");
792
+ var import_ed255193 = require("@mysten/sui.js/keypairs/ed25519");
793
+ var import_secp256r1 = require("@mysten/sui.js/keypairs/secp256r1");
794
+ var import_secp256k1 = require("@mysten/sui.js/keypairs/secp256k1");
795
+ var import_multisig = require("@mysten/sui.js/multisig");
796
+ var import_utils7 = require("@mysten/sui.js/utils");
797
+ var import_cryptography = require("@mysten/sui.js/cryptography");
798
+
799
+ // src/libs/bcs/bcs.ts
800
+ var import_bcs2 = require("@mysten/bcs");
801
+ var import_utils5 = require("@mysten/sui.js/utils");
802
+
803
+ // src/libs/bcs/typeTagSerializer.ts
804
+ var import_bcs = require("@mysten/bcs");
805
+ var import_utils4 = require("@mysten/sui.js/utils");
806
+ var VECTOR_REGEX = /^vector<(.+)>$/;
807
+ var STRUCT_REGEX = /^([^:]+)::([^:]+)::([^<]+)(<(.+)>)?/;
808
+ var TypeTagSerializer = class _TypeTagSerializer {
809
+ static parseFromStr(str, normalizeAddress = false) {
810
+ if (str === "address") {
811
+ return { address: null };
812
+ } else if (str === "bool") {
813
+ return { bool: null };
814
+ } else if (str === "u8") {
815
+ return { u8: null };
816
+ } else if (str === "u16") {
817
+ return { u16: null };
818
+ } else if (str === "u32") {
819
+ return { u32: null };
820
+ } else if (str === "u64") {
821
+ return { u64: null };
822
+ } else if (str === "u128") {
823
+ return { u128: null };
824
+ } else if (str === "u256") {
825
+ return { u256: null };
826
+ } else if (str === "signer") {
827
+ return { signer: null };
828
+ }
829
+ const vectorMatch = str.match(VECTOR_REGEX);
830
+ if (vectorMatch) {
831
+ return {
832
+ vector: _TypeTagSerializer.parseFromStr(
833
+ vectorMatch[1],
834
+ normalizeAddress
835
+ )
836
+ };
837
+ }
838
+ const structMatch = str.match(STRUCT_REGEX);
839
+ if (structMatch) {
840
+ const address = normalizeAddress ? (0, import_utils4.normalizeSuiAddress)(structMatch[1]) : structMatch[1];
841
+ return {
842
+ struct: {
843
+ address,
844
+ module: structMatch[2],
845
+ name: structMatch[3],
846
+ typeParams: structMatch[5] === void 0 ? [] : _TypeTagSerializer.parseStructTypeArgs(
847
+ structMatch[5],
848
+ normalizeAddress
849
+ )
850
+ }
851
+ };
852
+ }
853
+ throw new Error(
854
+ `Encountered unexpected token when parsing type args for ${str}`
855
+ );
856
+ }
857
+ static parseStructTypeArgs(str, normalizeAddress = false) {
858
+ return (0, import_bcs.splitGenericParameters)(str).map(
859
+ (tok) => _TypeTagSerializer.parseFromStr(tok, normalizeAddress)
860
+ );
861
+ }
862
+ static tagToString(tag) {
863
+ if ("bool" in tag) {
864
+ return "bool";
865
+ }
866
+ if ("u8" in tag) {
867
+ return "u8";
868
+ }
869
+ if ("u16" in tag) {
870
+ return "u16";
871
+ }
872
+ if ("u32" in tag) {
873
+ return "u32";
874
+ }
875
+ if ("u64" in tag) {
876
+ return "u64";
877
+ }
878
+ if ("u128" in tag) {
879
+ return "u128";
880
+ }
881
+ if ("u256" in tag) {
882
+ return "u256";
883
+ }
884
+ if ("address" in tag) {
885
+ return "address";
886
+ }
887
+ if ("signer" in tag) {
888
+ return "signer";
889
+ }
890
+ if ("vector" in tag) {
891
+ return `vector<${_TypeTagSerializer.tagToString(tag.vector)}>`;
892
+ }
893
+ if ("struct" in tag) {
894
+ const struct = tag.struct;
895
+ const typeParams = struct.typeParams.map(_TypeTagSerializer.tagToString).join(", ");
896
+ return `${struct.address}::${struct.module}::${struct.name}${typeParams ? `<${typeParams}>` : ""}`;
897
+ }
898
+ throw new Error("Invalid TypeTag");
899
+ }
900
+ };
901
+
902
+ // src/libs/bcs/bcs.ts
903
+ var bcsRegistry = new import_bcs2.BCS({ ...(0, import_bcs2.getSuiMoveConfig)() });
904
+ function unsafe_u64(options) {
905
+ return import_bcs2.bcs.u64({
906
+ name: "unsafe_u64",
907
+ ...options
908
+ }).transform({
909
+ input: (val) => val,
910
+ output: (val) => Number(val)
911
+ });
912
+ }
913
+ function optionEnum(type) {
914
+ return import_bcs2.bcs.enum("Option", {
915
+ None: null,
916
+ Some: type
917
+ });
918
+ }
919
+ function enumKind(type) {
920
+ return type.transform({
921
+ input: (val) => ({
922
+ [val.kind]: val
923
+ }),
924
+ output: (val) => {
925
+ const key = Object.keys(val)[0];
926
+ return { kind: key, ...val[key] };
927
+ }
928
+ });
929
+ }
930
+ var Address = import_bcs2.bcs.bytes(import_utils5.SUI_ADDRESS_LENGTH).transform({
931
+ input: (val) => typeof val === "string" ? (0, import_bcs2.fromHEX)(val) : val,
932
+ output: (val) => (0, import_bcs2.toHEX)(val)
933
+ });
934
+ var ObjectDigest = import_bcs2.bcs.vector(import_bcs2.bcs.u8()).transform({
935
+ name: "ObjectDigest",
936
+ input: (value) => (0, import_bcs2.fromB58)(value),
937
+ output: (value) => (0, import_bcs2.toB58)(new Uint8Array(value))
938
+ });
939
+ var SuiObjectRef = import_bcs2.bcs.struct("SuiObjectRef", {
940
+ objectId: Address,
941
+ version: import_bcs2.bcs.u64(),
942
+ digest: ObjectDigest
943
+ });
944
+ var SharedObjectRef = import_bcs2.bcs.struct("SharedObjectRef", {
945
+ objectId: Address,
946
+ initialSharedVersion: import_bcs2.bcs.u64(),
947
+ mutable: import_bcs2.bcs.bool()
948
+ });
949
+ var ObjectArg = import_bcs2.bcs.enum("ObjectArg", {
950
+ ImmOrOwned: SuiObjectRef,
951
+ Shared: SharedObjectRef
952
+ });
953
+ var CallArg = import_bcs2.bcs.enum("CallArg", {
954
+ Pure: import_bcs2.bcs.vector(import_bcs2.bcs.u8()),
955
+ Object: ObjectArg,
956
+ ObjVec: import_bcs2.bcs.vector(ObjectArg)
957
+ });
958
+ var TypeTag = import_bcs2.bcs.enum("TypeTag", {
959
+ bool: null,
960
+ u8: null,
961
+ u64: null,
962
+ u128: null,
963
+ address: null,
964
+ signer: null,
965
+ vector: import_bcs2.bcs.lazy(() => TypeTag),
966
+ struct: import_bcs2.bcs.lazy(() => StructTag),
967
+ u16: null,
968
+ u32: null,
969
+ u256: null
970
+ });
971
+ var Argument = enumKind(
972
+ import_bcs2.bcs.enum("Argument", {
973
+ GasCoin: null,
974
+ Input: import_bcs2.bcs.struct("Input", { index: import_bcs2.bcs.u16() }),
975
+ Result: import_bcs2.bcs.struct("Result", { index: import_bcs2.bcs.u16() }),
976
+ NestedResult: import_bcs2.bcs.struct("NestedResult", {
977
+ index: import_bcs2.bcs.u16(),
978
+ resultIndex: import_bcs2.bcs.u16()
979
+ })
980
+ })
981
+ );
982
+ var ProgrammableMoveCall = import_bcs2.bcs.struct("ProgrammableMoveCall", {
983
+ package: Address,
984
+ module: import_bcs2.bcs.string(),
985
+ function: import_bcs2.bcs.string(),
986
+ type_arguments: import_bcs2.bcs.vector(TypeTag),
987
+ arguments: import_bcs2.bcs.vector(Argument)
988
+ }).transform({
989
+ // TODO: add type for the input data
990
+ input: (data) => {
991
+ const [pkg, module2, fun] = data.target.split("::");
992
+ const type_arguments = data.typeArguments.map(
993
+ (tag) => TypeTagSerializer.parseFromStr(tag, true)
994
+ );
995
+ return {
996
+ package: (0, import_utils5.normalizeSuiAddress)(pkg),
997
+ module: module2,
998
+ function: fun,
999
+ type_arguments,
1000
+ arguments: data.arguments
1001
+ };
1002
+ },
1003
+ output: (data) => {
1004
+ return {
1005
+ target: [data.package, data.module, data.function].join(
1006
+ "::"
1007
+ ),
1008
+ arguments: data.arguments,
1009
+ typeArguments: data.type_arguments.map(TypeTagSerializer.tagToString)
1010
+ };
1011
+ }
1012
+ });
1013
+ var Transaction = enumKind(
1014
+ import_bcs2.bcs.enum("Transaction", {
1015
+ /**
1016
+ * A Move Call - any public Move function can be called via
1017
+ * this transaction. The results can be used that instant to pass
1018
+ * into the next transaction.
1019
+ */
1020
+ MoveCall: ProgrammableMoveCall,
1021
+ /**
1022
+ * Transfer vector of objects to a receiver.
1023
+ */
1024
+ TransferObjects: import_bcs2.bcs.struct("TransferObjects", {
1025
+ objects: import_bcs2.bcs.vector(Argument),
1026
+ address: Argument
1027
+ }),
1028
+ /**
1029
+ * Split `amount` from a `coin`.
1030
+ */
1031
+ SplitCoins: import_bcs2.bcs.struct("SplitCoins", {
1032
+ coin: Argument,
1033
+ amounts: import_bcs2.bcs.vector(Argument)
1034
+ }),
1035
+ /**
1036
+ * Merge Vector of Coins (`sources`) into a `destination`.
1037
+ */
1038
+ MergeCoins: import_bcs2.bcs.struct("MergeCoins", {
1039
+ destination: Argument,
1040
+ sources: import_bcs2.bcs.vector(Argument)
1041
+ }),
1042
+ /**
1043
+ * Publish a Move module.
1044
+ */
1045
+ Publish: import_bcs2.bcs.struct("Publish", {
1046
+ modules: import_bcs2.bcs.vector(import_bcs2.bcs.vector(import_bcs2.bcs.u8())),
1047
+ dependencies: import_bcs2.bcs.vector(Address)
1048
+ }),
1049
+ /**
1050
+ * Build a vector of objects using the input arguments.
1051
+ * It is impossible to construct a `vector<T: key>` otherwise,
1052
+ * so this call serves a utility function.
1053
+ */
1054
+ MakeMoveVec: import_bcs2.bcs.struct("MakeMoveVec", {
1055
+ type: optionEnum(TypeTag),
1056
+ objects: import_bcs2.bcs.vector(Argument)
1057
+ }),
1058
+ /** */
1059
+ Upgrade: import_bcs2.bcs.struct("Upgrade", {
1060
+ modules: import_bcs2.bcs.vector(import_bcs2.bcs.vector(import_bcs2.bcs.u8())),
1061
+ dependencies: import_bcs2.bcs.vector(Address),
1062
+ packageId: Address,
1063
+ ticket: Argument
1064
+ })
1065
+ })
1066
+ );
1067
+ var ProgrammableTransaction = import_bcs2.bcs.struct("ProgrammableTransaction", {
1068
+ inputs: import_bcs2.bcs.vector(CallArg),
1069
+ transactions: import_bcs2.bcs.vector(Transaction)
1070
+ });
1071
+ var TransactionKind = import_bcs2.bcs.enum("TransactionKind", {
1072
+ ProgrammableTransaction,
1073
+ ChangeEpoch: null,
1074
+ Genesis: null,
1075
+ ConsensusCommitPrologue: null
1076
+ });
1077
+ var TransactionExpiration = import_bcs2.bcs.enum("TransactionExpiration", {
1078
+ None: null,
1079
+ Epoch: unsafe_u64()
1080
+ });
1081
+ var StructTag = import_bcs2.bcs.struct("StructTag", {
1082
+ address: Address,
1083
+ module: import_bcs2.bcs.string(),
1084
+ name: import_bcs2.bcs.string(),
1085
+ typeParams: import_bcs2.bcs.vector(TypeTag)
1086
+ });
1087
+ var GasData = import_bcs2.bcs.struct("GasData", {
1088
+ payment: import_bcs2.bcs.vector(SuiObjectRef),
1089
+ owner: Address,
1090
+ price: import_bcs2.bcs.u64(),
1091
+ budget: import_bcs2.bcs.u64()
1092
+ });
1093
+ var TransactionDataV1 = import_bcs2.bcs.struct("TransactionDataV1", {
1094
+ kind: TransactionKind,
1095
+ sender: Address,
1096
+ gasData: GasData,
1097
+ expiration: TransactionExpiration
1098
+ });
1099
+ var TransactionData = import_bcs2.bcs.enum("TransactionData", {
1100
+ V1: TransactionDataV1
1101
+ });
1102
+ var SenderSignedData = import_bcs2.bcs.struct("SenderSignedData", {
1103
+ data: TransactionData,
1104
+ txSignatures: import_bcs2.bcs.vector(import_bcs2.bcs.vector(import_bcs2.bcs.u8()))
1105
+ });
1106
+ var CompressedSignature = import_bcs2.bcs.enum("CompressedSignature", {
1107
+ ED25519: import_bcs2.bcs.fixedArray(64, import_bcs2.bcs.u8()),
1108
+ Secp256k1: import_bcs2.bcs.fixedArray(64, import_bcs2.bcs.u8()),
1109
+ Secp256r1: import_bcs2.bcs.fixedArray(64, import_bcs2.bcs.u8())
1110
+ });
1111
+ var PublicKey = import_bcs2.bcs.enum("PublicKey", {
1112
+ ED25519: import_bcs2.bcs.fixedArray(32, import_bcs2.bcs.u8()),
1113
+ Secp256k1: import_bcs2.bcs.fixedArray(33, import_bcs2.bcs.u8()),
1114
+ Secp256r1: import_bcs2.bcs.fixedArray(33, import_bcs2.bcs.u8())
1115
+ });
1116
+ var MultiSigPkMap = import_bcs2.bcs.struct("MultiSigPkMap", {
1117
+ pubKey: PublicKey,
1118
+ weight: import_bcs2.bcs.u8()
1119
+ });
1120
+ var MultiSigPublicKey = import_bcs2.bcs.struct("MultiSigPublicKey", {
1121
+ pk_map: import_bcs2.bcs.vector(MultiSigPkMap),
1122
+ threshold: import_bcs2.bcs.u16()
1123
+ });
1124
+ var MultiSig = import_bcs2.bcs.struct("MultiSig", {
1125
+ sigs: import_bcs2.bcs.vector(CompressedSignature),
1126
+ bitmap: import_bcs2.bcs.u16(),
1127
+ multisig_pk: MultiSigPublicKey
1128
+ });
1129
+ var suiBcs = {
1130
+ ...import_bcs2.bcs,
1131
+ U8: import_bcs2.bcs.u8(),
1132
+ U16: import_bcs2.bcs.u16(),
1133
+ U32: import_bcs2.bcs.u32(),
1134
+ U64: import_bcs2.bcs.u64(),
1135
+ U128: import_bcs2.bcs.u128(),
1136
+ U256: import_bcs2.bcs.u256(),
1137
+ ULEB128: import_bcs2.bcs.uleb128(),
1138
+ Bool: import_bcs2.bcs.bool(),
1139
+ String: import_bcs2.bcs.string(),
1140
+ Address,
1141
+ Argument,
1142
+ CallArg,
1143
+ CompressedSignature,
1144
+ GasData,
1145
+ MultiSig,
1146
+ MultiSigPkMap,
1147
+ MultiSigPublicKey,
1148
+ ObjectArg,
1149
+ ObjectDigest,
1150
+ ProgrammableMoveCall,
1151
+ ProgrammableTransaction,
1152
+ PublicKey,
1153
+ SenderSignedData,
1154
+ SharedObjectRef,
1155
+ StructTag,
1156
+ SuiObjectRef,
1157
+ Transaction,
1158
+ TransactionData,
1159
+ TransactionDataV1,
1160
+ TransactionExpiration,
1161
+ TransactionKind,
1162
+ TypeTag,
1163
+ // preserve backwards compatibility with old bcs export
1164
+ ser: bcsRegistry.ser.bind(bcsRegistry),
1165
+ de: bcsRegistry.de.bind(bcsRegistry),
1166
+ getTypeInterface: bcsRegistry.getTypeInterface.bind(bcsRegistry),
1167
+ hasType: bcsRegistry.hasType.bind(bcsRegistry),
1168
+ parseTypeName: bcsRegistry.parseTypeName.bind(bcsRegistry),
1169
+ registerAddressType: bcsRegistry.registerAddressType.bind(bcsRegistry),
1170
+ registerAlias: bcsRegistry.registerAlias.bind(bcsRegistry),
1171
+ registerBcsType: bcsRegistry.registerBcsType.bind(bcsRegistry),
1172
+ registerEnumType: bcsRegistry.registerEnumType.bind(bcsRegistry),
1173
+ registerStructType: bcsRegistry.registerStructType.bind(bcsRegistry),
1174
+ registerType: bcsRegistry.registerType.bind(bcsRegistry),
1175
+ types: bcsRegistry.types
1176
+ };
1177
+ bcsRegistry.registerBcsType(
1178
+ "utf8string",
1179
+ () => import_bcs2.bcs.string({ name: "utf8string" })
1180
+ );
1181
+ bcsRegistry.registerBcsType("unsafe_u64", () => unsafe_u64());
1182
+ bcsRegistry.registerBcsType("enumKind", (T) => enumKind(T));
1183
+ [
1184
+ Address,
1185
+ Argument,
1186
+ CallArg,
1187
+ CompressedSignature,
1188
+ GasData,
1189
+ MultiSig,
1190
+ MultiSigPkMap,
1191
+ MultiSigPublicKey,
1192
+ ObjectArg,
1193
+ ObjectDigest,
1194
+ ProgrammableMoveCall,
1195
+ ProgrammableTransaction,
1196
+ PublicKey,
1197
+ SenderSignedData,
1198
+ SharedObjectRef,
1199
+ StructTag,
1200
+ SuiObjectRef,
1201
+ Transaction,
1202
+ TransactionData,
1203
+ TransactionDataV1,
1204
+ TransactionExpiration,
1205
+ TransactionKind,
1206
+ TypeTag
1207
+ ].forEach((type) => {
1208
+ bcsRegistry.registerBcsType(type.name, () => type);
1209
+ });
1210
+
1211
+ // src/libs/multiSig/multiSig.ts
1212
+ function toMultiSigAddress(pks, threshold) {
1213
+ if (pks.length > import_multisig.MAX_SIGNER_IN_MULTISIG) {
1214
+ throw new Error(
1215
+ `Max number of signers in a multisig is ${import_multisig.MAX_SIGNER_IN_MULTISIG}`
1216
+ );
1217
+ }
1218
+ if (pks.length < import_multisig.MIN_SIGNER_IN_MULTISIG) {
1219
+ throw new Error(
1220
+ `Min number of signers in a multisig is ${import_multisig.MIN_SIGNER_IN_MULTISIG}`
1221
+ );
1222
+ }
1223
+ const maxLength = 1 + 2 + pks.length * (1 + 64 + 1);
1224
+ const buf = new Uint8Array(maxLength);
1225
+ let offset = 0;
1226
+ buf.set([import_cryptography.SIGNATURE_SCHEME_TO_FLAG.MultiSig], offset);
1227
+ offset += 1;
1228
+ buf.set([threshold & 255, threshold >> 8], offset);
1229
+ offset += 2;
1230
+ let totalWeight = 0;
1231
+ for (let i = 0; i < pks.length; i++) {
1232
+ const { pubKey, weight } = pks[i];
1233
+ const flag = pubKey.flag();
1234
+ buf.set([flag], offset);
1235
+ offset += 1;
1236
+ buf.set(pubKey.toRawBytes(), offset);
1237
+ offset += pubKey.toRawBytes().length;
1238
+ buf.set([weight], offset);
1239
+ offset += 1;
1240
+ totalWeight += weight;
1241
+ }
1242
+ if (totalWeight < threshold) {
1243
+ throw new Error(`Total weight is less than threshold`);
1244
+ }
1245
+ const bufHash = (0, import_blake2b.blake2b)(buf.slice(0, offset), { dkLen: 32 });
1246
+ return (0, import_utils7.normalizeSuiAddress)((0, import_utils6.bytesToHex)(bufHash));
1247
+ }
1248
+ function combinePartialSigs(sigs, pks, threshold) {
1249
+ if (sigs.length > import_multisig.MAX_SIGNER_IN_MULTISIG) {
1250
+ throw new Error(
1251
+ `Max number of signers in a multisig is ${import_multisig.MAX_SIGNER_IN_MULTISIG}`
1252
+ );
1253
+ }
1254
+ const multiSigPk = {
1255
+ pk_map: pks.map((pk) => toPkEnumWeightPair(pk)),
1256
+ threshold
1257
+ };
1258
+ let bitmap = 0;
1259
+ const compressedSigs = new Array(sigs.length);
1260
+ for (let i = 0; i < sigs.length; i++) {
1261
+ const parsed = toSingleSignaturePubkeyPair(sigs[i]);
1262
+ const bytes2 = Array.from(parsed.signature.map((x) => Number(x)));
1263
+ if (parsed.signatureScheme === "ED25519") {
1264
+ compressedSigs[i] = { ED25519: bytes2 };
1265
+ } else if (parsed.signatureScheme === "Secp256k1") {
1266
+ compressedSigs[i] = { Secp256k1: bytes2 };
1267
+ } else if (parsed.signatureScheme === "Secp256r1") {
1268
+ compressedSigs[i] = { Secp256r1: bytes2 };
1269
+ }
1270
+ for (let j = 0; j < pks.length; j++) {
1271
+ if (parsed.pubKey.equals(pks[j].pubKey)) {
1272
+ bitmap |= 1 << j;
1273
+ break;
1274
+ }
1275
+ }
1276
+ }
1277
+ const multiSig = {
1278
+ sigs: compressedSigs,
1279
+ bitmap,
1280
+ multisig_pk: multiSigPk
1281
+ };
1282
+ const bytes = suiBcs.MultiSig.serialize(multiSig).toBytes();
1283
+ const tmp = new Uint8Array(bytes.length + 1);
1284
+ tmp.set([import_cryptography.SIGNATURE_SCHEME_TO_FLAG.MultiSig], 0);
1285
+ tmp.set(bytes, 1);
1286
+ return (0, import_utils7.toB64)(tmp);
1287
+ }
1288
+ function toPkEnumWeightPair(pair) {
1289
+ const pk_bytes = Array.from(pair.pubKey.toBytes().map((x) => Number(x)));
1290
+ switch (pair.pubKey.flag()) {
1291
+ case import_cryptography.SIGNATURE_SCHEME_TO_FLAG["Secp256k1"]:
1292
+ return {
1293
+ pubKey: {
1294
+ Secp256k1: pk_bytes
1295
+ },
1296
+ weight: pair.weight
1297
+ };
1298
+ case import_cryptography.SIGNATURE_SCHEME_TO_FLAG["Secp256r1"]:
1299
+ return {
1300
+ pubKey: {
1301
+ Secp256r1: pk_bytes
1302
+ },
1303
+ weight: pair.weight
1304
+ };
1305
+ case import_cryptography.SIGNATURE_SCHEME_TO_FLAG["ED25519"]:
1306
+ return {
1307
+ pubKey: {
1308
+ ED25519: pk_bytes
1309
+ },
1310
+ weight: pair.weight
1311
+ };
1312
+ default:
1313
+ throw new Error("Unsupported signature scheme");
1314
+ }
1315
+ }
1316
+ function toSingleSignaturePubkeyPair(serializedSignature) {
1317
+ const res = toParsedSignaturePubkeyPair(serializedSignature);
1318
+ if (res.length !== 1) {
1319
+ throw Error("Expected a single signature");
1320
+ }
1321
+ return res[0];
1322
+ }
1323
+ function toParsedSignaturePubkeyPair(serializedSignature) {
1324
+ const bytes = (0, import_utils7.fromB64)(serializedSignature);
1325
+ const signatureScheme = import_cryptography.SIGNATURE_FLAG_TO_SCHEME[bytes[0]];
1326
+ if (signatureScheme === "Zk") {
1327
+ throw new Error("Zk signature not supported");
1328
+ }
1329
+ if (signatureScheme === "MultiSig") {
1330
+ throw new Error("MultiSig signature not supported");
1331
+ }
1332
+ const SIGNATURE_SCHEME_TO_PUBLIC_KEY = {
1333
+ ED25519: import_ed255193.Ed25519PublicKey,
1334
+ Secp256k1: import_secp256k1.Secp256k1PublicKey,
1335
+ Secp256r1: import_secp256r1.Secp256r1PublicKey
1336
+ };
1337
+ const PublicKey3 = SIGNATURE_SCHEME_TO_PUBLIC_KEY[signatureScheme];
1338
+ const signature = bytes.slice(1, bytes.length - PublicKey3.SIZE);
1339
+ const pubKeyBytes = bytes.slice(1 + signature.length);
1340
+ const pubKey = new PublicKey3(pubKeyBytes);
1341
+ return [
1342
+ {
1343
+ signatureScheme,
1344
+ signature,
1345
+ pubKey
1346
+ }
1347
+ ];
1348
+ }
1349
+
1350
+ // src/libs/multiSig/publickey.ts
1351
+ var import_ed255194 = require("@mysten/sui.js/keypairs/ed25519");
1352
+ var import_utils8 = require("@mysten/sui.js/utils");
1353
+ function ed25519PublicKeyFromBase64(rawPubkey) {
1354
+ let bytes = (0, import_utils8.fromB64)(rawPubkey);
1355
+ if (bytes.length !== 32 && bytes.length !== 33)
1356
+ throw "invalid pubkey length";
1357
+ bytes = bytes.length === 33 ? bytes.slice(1) : bytes;
1358
+ return new import_ed255194.Ed25519PublicKey(bytes);
1359
+ }
1360
+
1361
+ // src/libs/multiSig/client.ts
1362
+ var MultiSigClient = class _MultiSigClient {
1363
+ constructor(pks, threshold) {
1364
+ this.pksWeightPairs = pks;
1365
+ this.threshold = threshold;
1366
+ }
1367
+ static fromRawPubkeys(rawPubkeys, weights, threshold) {
1368
+ const pks = rawPubkeys.map((rawPubkey, i) => {
1369
+ return {
1370
+ pubKey: ed25519PublicKeyFromBase64(rawPubkey),
1371
+ weight: weights[i]
1372
+ };
1373
+ });
1374
+ return new _MultiSigClient(pks, threshold);
1375
+ }
1376
+ multiSigAddress() {
1377
+ return toMultiSigAddress(this.pksWeightPairs, this.threshold);
1378
+ }
1379
+ combinePartialSigs(sigs) {
1380
+ return combinePartialSigs(sigs, this.pksWeightPairs, this.threshold);
1381
+ }
1382
+ };
787
1383
  // Annotate the CommonJS export names for ESM import in node:
788
1384
  0 && (module.exports = {
1385
+ MultiSigClient,
789
1386
  SuiAccountManager,
790
1387
  SuiKit,
791
1388
  SuiTxBlock,