@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.d.cts
CHANGED
|
@@ -208,7 +208,7 @@ interface SendBtcTransactionRequest {
|
|
|
208
208
|
* - `signPsbt` - reserved for PSBT-based actions when exposed
|
|
209
209
|
*/
|
|
210
210
|
interface WalletAdapter {
|
|
211
|
-
/** Signs an SDK plaintext message and returns the wallet signature. */
|
|
211
|
+
/** Signs an SDK plaintext message and returns the wallet signature. BTC adapters may return base64 BIP-322 or hex-encoded signature bytes. */
|
|
212
212
|
signMessage?: (request: SignMessageRequest) => Promise<string>;
|
|
213
213
|
/** Signs an SDK-provided BTC PSBT and returns the signed PSBT as base64. */
|
|
214
214
|
signPsbt?: (request: SignPsbtRequest) => Promise<string>;
|
|
@@ -219,7 +219,7 @@ interface WalletAdapter {
|
|
|
219
219
|
}
|
|
220
220
|
/** Signature payload submitted to a sign-message action. */
|
|
221
221
|
interface SignatureInfo {
|
|
222
|
-
/** Wallet signature over the action message. */
|
|
222
|
+
/** Wallet signature over the action message. BTC signatures may be base64 BIP-322 or hex-encoded bytes. */
|
|
223
223
|
signature: string;
|
|
224
224
|
/** Chain used to produce the signature. */
|
|
225
225
|
chain: Chain;
|
package/dist/index.d.ts
CHANGED
|
@@ -208,7 +208,7 @@ interface SendBtcTransactionRequest {
|
|
|
208
208
|
* - `signPsbt` - reserved for PSBT-based actions when exposed
|
|
209
209
|
*/
|
|
210
210
|
interface WalletAdapter {
|
|
211
|
-
/** Signs an SDK plaintext message and returns the wallet signature. */
|
|
211
|
+
/** Signs an SDK plaintext message and returns the wallet signature. BTC adapters may return base64 BIP-322 or hex-encoded signature bytes. */
|
|
212
212
|
signMessage?: (request: SignMessageRequest) => Promise<string>;
|
|
213
213
|
/** Signs an SDK-provided BTC PSBT and returns the signed PSBT as base64. */
|
|
214
214
|
signPsbt?: (request: SignPsbtRequest) => Promise<string>;
|
|
@@ -219,7 +219,7 @@ interface WalletAdapter {
|
|
|
219
219
|
}
|
|
220
220
|
/** Signature payload submitted to a sign-message action. */
|
|
221
221
|
interface SignatureInfo {
|
|
222
|
-
/** Wallet signature over the action message. */
|
|
222
|
+
/** Wallet signature over the action message. BTC signatures may be base64 BIP-322 or hex-encoded bytes. */
|
|
223
223
|
signature: string;
|
|
224
224
|
/** Chain used to produce the signature. */
|
|
225
225
|
chain: Chain;
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { encodeFunctionData, createPublicClient, http, isAddress, getAddress } from 'viem';
|
|
1
|
+
import { encodeFunctionData, createPublicClient, http, isAddress, getAddress, isHex, bytesToHex } from 'viem';
|
|
2
2
|
import { mainnet } from 'viem/chains';
|
|
3
3
|
import { Actor, HttpAgent } from '@icp-sdk/core/agent';
|
|
4
4
|
import { Principal } from '@icp-sdk/core/principal';
|
|
5
|
+
import { base64, base64nopad } from '@scure/base';
|
|
5
6
|
import { idlLabelToId } from '@icp-sdk/core/candid';
|
|
6
|
-
import { encodeIcrcAccount } from '@
|
|
7
|
-
import { Principal as Principal$1 } from '@dfinity/principal';
|
|
7
|
+
import { encodeIcrcAccount } from '@icp-sdk/canisters/ledger/icrc';
|
|
8
8
|
import { validate, Network } from 'bitcoin-address-validation';
|
|
9
9
|
|
|
10
10
|
// src/client.ts
|
|
@@ -1064,17 +1064,68 @@ function executeWith(options) {
|
|
|
1064
1064
|
}
|
|
1065
1065
|
};
|
|
1066
1066
|
}
|
|
1067
|
-
|
|
1068
|
-
|
|
1067
|
+
var HEX_PREFIX = "0x";
|
|
1068
|
+
var HEX_BYTE_CHAR_LENGTH = 2;
|
|
1069
|
+
var BASE64_PADDING = "=";
|
|
1070
|
+
function normalizeWalletSignature(signature, chain) {
|
|
1071
|
+
switch (chain) {
|
|
1072
|
+
case Chain.BTC:
|
|
1073
|
+
return normalizeBtcSignature(signature);
|
|
1074
|
+
case Chain.ETH:
|
|
1075
|
+
return normalizeHexSignature(signature);
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1069
1078
|
function normalizeHexSignature(signature) {
|
|
1070
|
-
if (!signature
|
|
1079
|
+
if (!isPrefixedHex(signature)) {
|
|
1071
1080
|
return signature;
|
|
1072
1081
|
}
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1082
|
+
return signature.slice(HEX_PREFIX.length);
|
|
1083
|
+
}
|
|
1084
|
+
function normalizeBtcSignature(signature) {
|
|
1085
|
+
const signatureWithoutPrefix = signature.startsWith(HEX_PREFIX) ? signature.slice(HEX_PREFIX.length) : signature;
|
|
1086
|
+
if (isHexBytes(signatureWithoutPrefix)) {
|
|
1087
|
+
return signatureWithoutPrefix;
|
|
1088
|
+
}
|
|
1089
|
+
if (signature.startsWith(HEX_PREFIX)) {
|
|
1090
|
+
throw invalidBtcSignatureFormatError();
|
|
1091
|
+
}
|
|
1092
|
+
return bytesToUnprefixedHex(decodeBase64Signature(signature));
|
|
1093
|
+
}
|
|
1094
|
+
function isHexBytes(signature) {
|
|
1095
|
+
return signature.length > 0 && signature.length % HEX_BYTE_CHAR_LENGTH === 0 && isHex(`${HEX_PREFIX}${signature}`);
|
|
1096
|
+
}
|
|
1097
|
+
function decodeBase64Signature(signature) {
|
|
1098
|
+
try {
|
|
1099
|
+
const bytes = decodeBase64Bytes(signature);
|
|
1100
|
+
if (bytes.length === 0) {
|
|
1101
|
+
throw invalidBtcSignatureFormatError();
|
|
1102
|
+
}
|
|
1103
|
+
return bytes;
|
|
1104
|
+
} catch (error) {
|
|
1105
|
+
if (error instanceof LiquidiumError) {
|
|
1106
|
+
throw error;
|
|
1107
|
+
}
|
|
1108
|
+
throw invalidBtcSignatureFormatError(error);
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
function bytesToUnprefixedHex(bytes) {
|
|
1112
|
+
return normalizeHexSignature(bytesToHex(bytes));
|
|
1113
|
+
}
|
|
1114
|
+
function isPrefixedHex(signature) {
|
|
1115
|
+
return signature.length > HEX_PREFIX.length && isHex(signature);
|
|
1116
|
+
}
|
|
1117
|
+
function decodeBase64Bytes(signature) {
|
|
1118
|
+
if (signature.includes(BASE64_PADDING)) {
|
|
1119
|
+
return base64.decode(signature);
|
|
1076
1120
|
}
|
|
1077
|
-
return
|
|
1121
|
+
return base64nopad.decode(signature);
|
|
1122
|
+
}
|
|
1123
|
+
function invalidBtcSignatureFormatError(cause) {
|
|
1124
|
+
return new LiquidiumError(
|
|
1125
|
+
LiquidiumErrorCode.SIGNATURE_ERROR,
|
|
1126
|
+
"BTC signature must be hex or base64-encoded bytes",
|
|
1127
|
+
cause
|
|
1128
|
+
);
|
|
1078
1129
|
}
|
|
1079
1130
|
|
|
1080
1131
|
// src/modules/accounts/mappers.ts
|
|
@@ -1092,7 +1143,10 @@ function mapCreateAccountRequestToRegisterProfileRequest(request) {
|
|
|
1092
1143
|
},
|
|
1093
1144
|
signature_info: {
|
|
1094
1145
|
Wallet: {
|
|
1095
|
-
signature:
|
|
1146
|
+
signature: normalizeWalletSignature(
|
|
1147
|
+
request.signatureInfo.signature,
|
|
1148
|
+
request.signatureInfo.chain
|
|
1149
|
+
),
|
|
1096
1150
|
chain: mapAccountChainToLendingChainVariant(
|
|
1097
1151
|
request.signatureInfo.chain
|
|
1098
1152
|
),
|
|
@@ -3206,7 +3260,7 @@ function getIcrcAccountSupplyTarget(profileId, request) {
|
|
|
3206
3260
|
owner: poolPrincipal.toText(),
|
|
3207
3261
|
subaccount,
|
|
3208
3262
|
account: encodeIcrcAccount({
|
|
3209
|
-
owner:
|
|
3263
|
+
owner: poolPrincipal,
|
|
3210
3264
|
subaccount
|
|
3211
3265
|
})
|
|
3212
3266
|
};
|
|
@@ -4556,7 +4610,7 @@ function createTransferErc20Transaction(params) {
|
|
|
4556
4610
|
}
|
|
4557
4611
|
function createDepositErc20Transaction(params) {
|
|
4558
4612
|
const expectedDestinationAccount = encodeIcrcAccount({
|
|
4559
|
-
owner: Principal
|
|
4613
|
+
owner: Principal.fromText(params.poolId),
|
|
4560
4614
|
subaccount: encodeInflowSubaccount({
|
|
4561
4615
|
action: params.action,
|
|
4562
4616
|
principal: Principal.fromText(params.profileId)
|
|
@@ -4868,7 +4922,10 @@ var LendingModule = class {
|
|
|
4868
4922
|
},
|
|
4869
4923
|
signature_info: {
|
|
4870
4924
|
Wallet: {
|
|
4871
|
-
signature:
|
|
4925
|
+
signature: normalizeWalletSignature(
|
|
4926
|
+
signatureInfo.signature,
|
|
4927
|
+
signatureInfo.chain
|
|
4928
|
+
),
|
|
4872
4929
|
chain: mapWalletChainToLendingChain(signatureInfo.chain),
|
|
4873
4930
|
account: request.signerWalletAddress
|
|
4874
4931
|
}
|
|
@@ -5006,7 +5063,10 @@ var LendingModule = class {
|
|
|
5006
5063
|
},
|
|
5007
5064
|
signature_info: {
|
|
5008
5065
|
Wallet: {
|
|
5009
|
-
signature:
|
|
5066
|
+
signature: normalizeWalletSignature(
|
|
5067
|
+
signatureInfo.signature,
|
|
5068
|
+
signatureInfo.chain
|
|
5069
|
+
),
|
|
5010
5070
|
chain: mapWalletChainToLendingChain(signatureInfo.chain),
|
|
5011
5071
|
account: request.signerWalletAddress
|
|
5012
5072
|
}
|