@liquidium/client 0.3.1 → 0.3.2
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.cjs +71 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +72 -11
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -4,6 +4,7 @@ var viem = require('viem');
|
|
|
4
4
|
var chains = require('viem/chains');
|
|
5
5
|
var agent = require('@icp-sdk/core/agent');
|
|
6
6
|
var principal = require('@icp-sdk/core/principal');
|
|
7
|
+
var base = require('@scure/base');
|
|
7
8
|
var candid = require('@icp-sdk/core/candid');
|
|
8
9
|
var ledgerIcrc = require('@dfinity/ledger-icrc');
|
|
9
10
|
var principal$1 = require('@dfinity/principal');
|
|
@@ -1066,17 +1067,68 @@ function executeWith(options) {
|
|
|
1066
1067
|
}
|
|
1067
1068
|
};
|
|
1068
1069
|
}
|
|
1069
|
-
|
|
1070
|
-
|
|
1070
|
+
var HEX_PREFIX = "0x";
|
|
1071
|
+
var HEX_BYTE_CHAR_LENGTH = 2;
|
|
1072
|
+
var BASE64_PADDING = "=";
|
|
1073
|
+
function normalizeWalletSignature(signature, chain) {
|
|
1074
|
+
switch (chain) {
|
|
1075
|
+
case Chain.BTC:
|
|
1076
|
+
return normalizeBtcSignature(signature);
|
|
1077
|
+
case Chain.ETH:
|
|
1078
|
+
return normalizeHexSignature(signature);
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1071
1081
|
function normalizeHexSignature(signature) {
|
|
1072
|
-
if (!signature
|
|
1082
|
+
if (!isPrefixedHex(signature)) {
|
|
1073
1083
|
return signature;
|
|
1074
1084
|
}
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1085
|
+
return signature.slice(HEX_PREFIX.length);
|
|
1086
|
+
}
|
|
1087
|
+
function normalizeBtcSignature(signature) {
|
|
1088
|
+
const signatureWithoutPrefix = signature.startsWith(HEX_PREFIX) ? signature.slice(HEX_PREFIX.length) : signature;
|
|
1089
|
+
if (isHexBytes(signatureWithoutPrefix)) {
|
|
1090
|
+
return signatureWithoutPrefix;
|
|
1091
|
+
}
|
|
1092
|
+
if (signature.startsWith(HEX_PREFIX)) {
|
|
1093
|
+
throw invalidBtcSignatureFormatError();
|
|
1094
|
+
}
|
|
1095
|
+
return bytesToUnprefixedHex(decodeBase64Signature(signature));
|
|
1096
|
+
}
|
|
1097
|
+
function isHexBytes(signature) {
|
|
1098
|
+
return signature.length > 0 && signature.length % HEX_BYTE_CHAR_LENGTH === 0 && viem.isHex(`${HEX_PREFIX}${signature}`);
|
|
1099
|
+
}
|
|
1100
|
+
function decodeBase64Signature(signature) {
|
|
1101
|
+
try {
|
|
1102
|
+
const bytes = decodeBase64Bytes(signature);
|
|
1103
|
+
if (bytes.length === 0) {
|
|
1104
|
+
throw invalidBtcSignatureFormatError();
|
|
1105
|
+
}
|
|
1106
|
+
return bytes;
|
|
1107
|
+
} catch (error) {
|
|
1108
|
+
if (error instanceof LiquidiumError) {
|
|
1109
|
+
throw error;
|
|
1110
|
+
}
|
|
1111
|
+
throw invalidBtcSignatureFormatError(error);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
function bytesToUnprefixedHex(bytes) {
|
|
1115
|
+
return normalizeHexSignature(viem.bytesToHex(bytes));
|
|
1116
|
+
}
|
|
1117
|
+
function isPrefixedHex(signature) {
|
|
1118
|
+
return signature.length > HEX_PREFIX.length && viem.isHex(signature);
|
|
1119
|
+
}
|
|
1120
|
+
function decodeBase64Bytes(signature) {
|
|
1121
|
+
if (signature.includes(BASE64_PADDING)) {
|
|
1122
|
+
return base.base64.decode(signature);
|
|
1078
1123
|
}
|
|
1079
|
-
return
|
|
1124
|
+
return base.base64nopad.decode(signature);
|
|
1125
|
+
}
|
|
1126
|
+
function invalidBtcSignatureFormatError(cause) {
|
|
1127
|
+
return new LiquidiumError(
|
|
1128
|
+
LiquidiumErrorCode.SIGNATURE_ERROR,
|
|
1129
|
+
"BTC signature must be hex or base64-encoded bytes",
|
|
1130
|
+
cause
|
|
1131
|
+
);
|
|
1080
1132
|
}
|
|
1081
1133
|
|
|
1082
1134
|
// src/modules/accounts/mappers.ts
|
|
@@ -1094,7 +1146,10 @@ function mapCreateAccountRequestToRegisterProfileRequest(request) {
|
|
|
1094
1146
|
},
|
|
1095
1147
|
signature_info: {
|
|
1096
1148
|
Wallet: {
|
|
1097
|
-
signature:
|
|
1149
|
+
signature: normalizeWalletSignature(
|
|
1150
|
+
request.signatureInfo.signature,
|
|
1151
|
+
request.signatureInfo.chain
|
|
1152
|
+
),
|
|
1098
1153
|
chain: mapAccountChainToLendingChainVariant(
|
|
1099
1154
|
request.signatureInfo.chain
|
|
1100
1155
|
),
|
|
@@ -4870,7 +4925,10 @@ var LendingModule = class {
|
|
|
4870
4925
|
},
|
|
4871
4926
|
signature_info: {
|
|
4872
4927
|
Wallet: {
|
|
4873
|
-
signature:
|
|
4928
|
+
signature: normalizeWalletSignature(
|
|
4929
|
+
signatureInfo.signature,
|
|
4930
|
+
signatureInfo.chain
|
|
4931
|
+
),
|
|
4874
4932
|
chain: mapWalletChainToLendingChain(signatureInfo.chain),
|
|
4875
4933
|
account: request.signerWalletAddress
|
|
4876
4934
|
}
|
|
@@ -5008,7 +5066,10 @@ var LendingModule = class {
|
|
|
5008
5066
|
},
|
|
5009
5067
|
signature_info: {
|
|
5010
5068
|
Wallet: {
|
|
5011
|
-
signature:
|
|
5069
|
+
signature: normalizeWalletSignature(
|
|
5070
|
+
signatureInfo.signature,
|
|
5071
|
+
signatureInfo.chain
|
|
5072
|
+
),
|
|
5012
5073
|
chain: mapWalletChainToLendingChain(signatureInfo.chain),
|
|
5013
5074
|
account: request.signerWalletAddress
|
|
5014
5075
|
}
|