@liquidium/client 0.3.1 → 0.3.3
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 +76 -16
- 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 +75 -15
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -4,9 +4,9 @@ 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
|
-
var
|
|
9
|
-
var principal$1 = require('@dfinity/principal');
|
|
9
|
+
var icrc = require('@icp-sdk/canisters/ledger/icrc');
|
|
10
10
|
var bitcoinAddressValidation = require('bitcoin-address-validation');
|
|
11
11
|
|
|
12
12
|
// src/client.ts
|
|
@@ -1066,17 +1066,68 @@ function executeWith(options) {
|
|
|
1066
1066
|
}
|
|
1067
1067
|
};
|
|
1068
1068
|
}
|
|
1069
|
-
|
|
1070
|
-
|
|
1069
|
+
var HEX_PREFIX = "0x";
|
|
1070
|
+
var HEX_BYTE_CHAR_LENGTH = 2;
|
|
1071
|
+
var BASE64_PADDING = "=";
|
|
1072
|
+
function normalizeWalletSignature(signature, chain) {
|
|
1073
|
+
switch (chain) {
|
|
1074
|
+
case Chain.BTC:
|
|
1075
|
+
return normalizeBtcSignature(signature);
|
|
1076
|
+
case Chain.ETH:
|
|
1077
|
+
return normalizeHexSignature(signature);
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1071
1080
|
function normalizeHexSignature(signature) {
|
|
1072
|
-
if (!signature
|
|
1081
|
+
if (!isPrefixedHex(signature)) {
|
|
1073
1082
|
return signature;
|
|
1074
1083
|
}
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1084
|
+
return signature.slice(HEX_PREFIX.length);
|
|
1085
|
+
}
|
|
1086
|
+
function normalizeBtcSignature(signature) {
|
|
1087
|
+
const signatureWithoutPrefix = signature.startsWith(HEX_PREFIX) ? signature.slice(HEX_PREFIX.length) : signature;
|
|
1088
|
+
if (isHexBytes(signatureWithoutPrefix)) {
|
|
1089
|
+
return signatureWithoutPrefix;
|
|
1090
|
+
}
|
|
1091
|
+
if (signature.startsWith(HEX_PREFIX)) {
|
|
1092
|
+
throw invalidBtcSignatureFormatError();
|
|
1093
|
+
}
|
|
1094
|
+
return bytesToUnprefixedHex(decodeBase64Signature(signature));
|
|
1095
|
+
}
|
|
1096
|
+
function isHexBytes(signature) {
|
|
1097
|
+
return signature.length > 0 && signature.length % HEX_BYTE_CHAR_LENGTH === 0 && viem.isHex(`${HEX_PREFIX}${signature}`);
|
|
1098
|
+
}
|
|
1099
|
+
function decodeBase64Signature(signature) {
|
|
1100
|
+
try {
|
|
1101
|
+
const bytes = decodeBase64Bytes(signature);
|
|
1102
|
+
if (bytes.length === 0) {
|
|
1103
|
+
throw invalidBtcSignatureFormatError();
|
|
1104
|
+
}
|
|
1105
|
+
return bytes;
|
|
1106
|
+
} catch (error) {
|
|
1107
|
+
if (error instanceof LiquidiumError) {
|
|
1108
|
+
throw error;
|
|
1109
|
+
}
|
|
1110
|
+
throw invalidBtcSignatureFormatError(error);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
function bytesToUnprefixedHex(bytes) {
|
|
1114
|
+
return normalizeHexSignature(viem.bytesToHex(bytes));
|
|
1115
|
+
}
|
|
1116
|
+
function isPrefixedHex(signature) {
|
|
1117
|
+
return signature.length > HEX_PREFIX.length && viem.isHex(signature);
|
|
1118
|
+
}
|
|
1119
|
+
function decodeBase64Bytes(signature) {
|
|
1120
|
+
if (signature.includes(BASE64_PADDING)) {
|
|
1121
|
+
return base.base64.decode(signature);
|
|
1078
1122
|
}
|
|
1079
|
-
return
|
|
1123
|
+
return base.base64nopad.decode(signature);
|
|
1124
|
+
}
|
|
1125
|
+
function invalidBtcSignatureFormatError(cause) {
|
|
1126
|
+
return new LiquidiumError(
|
|
1127
|
+
LiquidiumErrorCode.SIGNATURE_ERROR,
|
|
1128
|
+
"BTC signature must be hex or base64-encoded bytes",
|
|
1129
|
+
cause
|
|
1130
|
+
);
|
|
1080
1131
|
}
|
|
1081
1132
|
|
|
1082
1133
|
// src/modules/accounts/mappers.ts
|
|
@@ -1094,7 +1145,10 @@ function mapCreateAccountRequestToRegisterProfileRequest(request) {
|
|
|
1094
1145
|
},
|
|
1095
1146
|
signature_info: {
|
|
1096
1147
|
Wallet: {
|
|
1097
|
-
signature:
|
|
1148
|
+
signature: normalizeWalletSignature(
|
|
1149
|
+
request.signatureInfo.signature,
|
|
1150
|
+
request.signatureInfo.chain
|
|
1151
|
+
),
|
|
1098
1152
|
chain: mapAccountChainToLendingChainVariant(
|
|
1099
1153
|
request.signatureInfo.chain
|
|
1100
1154
|
),
|
|
@@ -3207,8 +3261,8 @@ function getIcrcAccountSupplyTarget(profileId, request) {
|
|
|
3207
3261
|
action: request.action,
|
|
3208
3262
|
owner: poolPrincipal.toText(),
|
|
3209
3263
|
subaccount,
|
|
3210
|
-
account:
|
|
3211
|
-
owner:
|
|
3264
|
+
account: icrc.encodeIcrcAccount({
|
|
3265
|
+
owner: poolPrincipal,
|
|
3212
3266
|
subaccount
|
|
3213
3267
|
})
|
|
3214
3268
|
};
|
|
@@ -4557,8 +4611,8 @@ function createTransferErc20Transaction(params) {
|
|
|
4557
4611
|
};
|
|
4558
4612
|
}
|
|
4559
4613
|
function createDepositErc20Transaction(params) {
|
|
4560
|
-
const expectedDestinationAccount =
|
|
4561
|
-
owner: principal
|
|
4614
|
+
const expectedDestinationAccount = icrc.encodeIcrcAccount({
|
|
4615
|
+
owner: principal.Principal.fromText(params.poolId),
|
|
4562
4616
|
subaccount: encodeInflowSubaccount({
|
|
4563
4617
|
action: params.action,
|
|
4564
4618
|
principal: principal.Principal.fromText(params.profileId)
|
|
@@ -4870,7 +4924,10 @@ var LendingModule = class {
|
|
|
4870
4924
|
},
|
|
4871
4925
|
signature_info: {
|
|
4872
4926
|
Wallet: {
|
|
4873
|
-
signature:
|
|
4927
|
+
signature: normalizeWalletSignature(
|
|
4928
|
+
signatureInfo.signature,
|
|
4929
|
+
signatureInfo.chain
|
|
4930
|
+
),
|
|
4874
4931
|
chain: mapWalletChainToLendingChain(signatureInfo.chain),
|
|
4875
4932
|
account: request.signerWalletAddress
|
|
4876
4933
|
}
|
|
@@ -5008,7 +5065,10 @@ var LendingModule = class {
|
|
|
5008
5065
|
},
|
|
5009
5066
|
signature_info: {
|
|
5010
5067
|
Wallet: {
|
|
5011
|
-
signature:
|
|
5068
|
+
signature: normalizeWalletSignature(
|
|
5069
|
+
signatureInfo.signature,
|
|
5070
|
+
signatureInfo.chain
|
|
5071
|
+
),
|
|
5012
5072
|
chain: mapWalletChainToLendingChain(signatureInfo.chain),
|
|
5013
5073
|
account: request.signerWalletAddress
|
|
5014
5074
|
}
|