lampamazaza-new-internal-utils 0.24.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/LICENSE +21 -0
- package/dist/_virtual/rolldown_runtime.cjs +43 -0
- package/dist/_virtual/rolldown_runtime.js +18 -0
- package/dist/config.cjs +82 -0
- package/dist/config.d.cts +42 -0
- package/dist/config.d.ts +42 -0
- package/dist/config.js +72 -0
- package/dist/errors/assert.cjs +11 -0
- package/dist/errors/assert.d.cts +11 -0
- package/dist/errors/assert.d.ts +11 -0
- package/dist/errors/assert.js +11 -0
- package/dist/errors/base.cjs +34 -0
- package/dist/errors/base.d.cts +21 -0
- package/dist/errors/base.d.ts +21 -0
- package/dist/errors/base.js +33 -0
- package/dist/errors/index.cjs +23 -0
- package/dist/errors/index.d.cts +11 -0
- package/dist/errors/index.d.ts +11 -0
- package/dist/errors/index.js +18 -0
- package/dist/errors/request.cjs +48 -0
- package/dist/errors/request.d.cts +61 -0
- package/dist/errors/request.d.ts +61 -0
- package/dist/errors/request.js +46 -0
- package/dist/errors/utils/isNetworkError.cjs +23 -0
- package/dist/errors/utils/isNetworkError.js +22 -0
- package/dist/errors/utils/toError.cjs +8 -0
- package/dist/errors/utils/toError.d.cts +4 -0
- package/dist/errors/utils/toError.d.ts +4 -0
- package/dist/errors/utils/toError.js +7 -0
- package/dist/index.cjs +125 -0
- package/dist/index.d.cts +30 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +30 -0
- package/dist/logger.d.cts +11 -0
- package/dist/logger.d.ts +11 -0
- package/dist/nearClient.cjs +18 -0
- package/dist/nearClient.d.cts +8 -0
- package/dist/nearClient.d.ts +8 -0
- package/dist/nearClient.js +18 -0
- package/dist/poaBridge/constants/blockchains.cjs +57 -0
- package/dist/poaBridge/constants/blockchains.d.cts +86 -0
- package/dist/poaBridge/constants/blockchains.d.ts +86 -0
- package/dist/poaBridge/constants/blockchains.js +54 -0
- package/dist/poaBridge/errors/withdrawal.cjs +52 -0
- package/dist/poaBridge/errors/withdrawal.d.cts +34 -0
- package/dist/poaBridge/errors/withdrawal.d.ts +34 -0
- package/dist/poaBridge/errors/withdrawal.js +50 -0
- package/dist/poaBridge/getPendingDeposits.cjs +9 -0
- package/dist/poaBridge/getPendingDeposits.d.cts +12 -0
- package/dist/poaBridge/getPendingDeposits.d.ts +13 -0
- package/dist/poaBridge/getPendingDeposits.js +9 -0
- package/dist/poaBridge/index.cjs +23 -0
- package/dist/poaBridge/index.d.cts +11 -0
- package/dist/poaBridge/index.d.ts +11 -0
- package/dist/poaBridge/index.js +18 -0
- package/dist/poaBridge/poaBridgeHttpClient/apis.cjs +38 -0
- package/dist/poaBridge/poaBridgeHttpClient/apis.d.cts +12 -0
- package/dist/poaBridge/poaBridgeHttpClient/apis.d.ts +12 -0
- package/dist/poaBridge/poaBridgeHttpClient/apis.js +32 -0
- package/dist/poaBridge/poaBridgeHttpClient/index.cjs +21 -0
- package/dist/poaBridge/poaBridgeHttpClient/index.d.cts +9 -0
- package/dist/poaBridge/poaBridgeHttpClient/index.d.ts +9 -0
- package/dist/poaBridge/poaBridgeHttpClient/index.js +16 -0
- package/dist/poaBridge/poaBridgeHttpClient/runtime.cjs +49 -0
- package/dist/poaBridge/poaBridgeHttpClient/runtime.js +47 -0
- package/dist/poaBridge/poaBridgeHttpClient/types.d.cts +161 -0
- package/dist/poaBridge/poaBridgeHttpClient/types.d.ts +161 -0
- package/dist/poaBridge/waitForWithdrawalCompletion.cjs +57 -0
- package/dist/poaBridge/waitForWithdrawalCompletion.d.cts +31 -0
- package/dist/poaBridge/waitForWithdrawalCompletion.d.ts +31 -0
- package/dist/poaBridge/waitForWithdrawalCompletion.js +56 -0
- package/dist/services/blockchainBalanceService.cjs +40 -0
- package/dist/services/blockchainBalanceService.d.cts +21 -0
- package/dist/services/blockchainBalanceService.d.ts +21 -0
- package/dist/services/blockchainBalanceService.js +37 -0
- package/dist/solverRelay/errors/intentSettlement.cjs +20 -0
- package/dist/solverRelay/errors/intentSettlement.d.cts +13 -0
- package/dist/solverRelay/errors/intentSettlement.d.ts +13 -0
- package/dist/solverRelay/errors/intentSettlement.js +20 -0
- package/dist/solverRelay/errors/quote.cjs +18 -0
- package/dist/solverRelay/errors/quote.d.cts +21 -0
- package/dist/solverRelay/errors/quote.d.ts +22 -0
- package/dist/solverRelay/errors/quote.js +18 -0
- package/dist/solverRelay/getQuote.cjs +49 -0
- package/dist/solverRelay/getQuote.d.cts +14 -0
- package/dist/solverRelay/getQuote.d.ts +14 -0
- package/dist/solverRelay/getQuote.js +49 -0
- package/dist/solverRelay/getStatus.cjs +26 -0
- package/dist/solverRelay/getStatus.d.cts +17 -0
- package/dist/solverRelay/getStatus.d.ts +18 -0
- package/dist/solverRelay/getStatus.js +26 -0
- package/dist/solverRelay/index.cjs +27 -0
- package/dist/solverRelay/index.d.cts +16 -0
- package/dist/solverRelay/index.d.ts +16 -0
- package/dist/solverRelay/index.js +22 -0
- package/dist/solverRelay/publishIntent.cjs +20 -0
- package/dist/solverRelay/publishIntent.d.cts +15 -0
- package/dist/solverRelay/publishIntent.d.ts +16 -0
- package/dist/solverRelay/publishIntent.js +20 -0
- package/dist/solverRelay/publishIntents.cjs +43 -0
- package/dist/solverRelay/publishIntents.d.cts +10 -0
- package/dist/solverRelay/publishIntents.d.ts +11 -0
- package/dist/solverRelay/publishIntents.js +42 -0
- package/dist/solverRelay/solverRelayHttpClient/apis.cjs +21 -0
- package/dist/solverRelay/solverRelayHttpClient/apis.d.cts +9 -0
- package/dist/solverRelay/solverRelayHttpClient/apis.d.ts +9 -0
- package/dist/solverRelay/solverRelayHttpClient/apis.js +18 -0
- package/dist/solverRelay/solverRelayHttpClient/index.cjs +18 -0
- package/dist/solverRelay/solverRelayHttpClient/index.d.cts +9 -0
- package/dist/solverRelay/solverRelayHttpClient/index.d.ts +9 -0
- package/dist/solverRelay/solverRelayHttpClient/index.js +13 -0
- package/dist/solverRelay/solverRelayHttpClient/runtime.cjs +60 -0
- package/dist/solverRelay/solverRelayHttpClient/runtime.js +58 -0
- package/dist/solverRelay/solverRelayHttpClient/types.d.cts +109 -0
- package/dist/solverRelay/solverRelayHttpClient/types.d.ts +109 -0
- package/dist/solverRelay/utils/parseFailedPublishError.cjs +40 -0
- package/dist/solverRelay/utils/parseFailedPublishError.d.cts +25 -0
- package/dist/solverRelay/utils/parseFailedPublishError.d.ts +26 -0
- package/dist/solverRelay/utils/parseFailedPublishError.js +39 -0
- package/dist/solverRelay/utils/quoteWithLog.cjs +21 -0
- package/dist/solverRelay/utils/quoteWithLog.d.cts +12 -0
- package/dist/solverRelay/utils/quoteWithLog.d.ts +14 -0
- package/dist/solverRelay/utils/quoteWithLog.js +21 -0
- package/dist/solverRelay/waitForIntentSettlement.cjs +52 -0
- package/dist/solverRelay/waitForIntentSettlement.d.cts +30 -0
- package/dist/solverRelay/waitForIntentSettlement.d.ts +30 -0
- package/dist/solverRelay/waitForIntentSettlement.js +52 -0
- package/dist/types/authHandle.cjs +22 -0
- package/dist/types/authHandle.d.cts +25 -0
- package/dist/types/authHandle.d.ts +25 -0
- package/dist/types/authHandle.js +16 -0
- package/dist/types/base.d.cts +45 -0
- package/dist/types/base.d.ts +45 -0
- package/dist/types/intentsUserId.d.cts +10 -0
- package/dist/types/intentsUserId.d.ts +10 -0
- package/dist/types/walletMessage.cjs +11 -0
- package/dist/types/walletMessage.d.cts +106 -0
- package/dist/types/walletMessage.d.ts +106 -0
- package/dist/types/walletMessage.js +5 -0
- package/dist/utils/abortSignal.cjs +19 -0
- package/dist/utils/abortSignal.js +18 -0
- package/dist/utils/appFee.cjs +20 -0
- package/dist/utils/appFee.d.cts +9 -0
- package/dist/utils/appFee.d.ts +9 -0
- package/dist/utils/appFee.js +15 -0
- package/dist/utils/assert.cjs +9 -0
- package/dist/utils/assert.d.cts +7 -0
- package/dist/utils/assert.d.ts +7 -0
- package/dist/utils/assert.js +9 -0
- package/dist/utils/authIdentity.cjs +56 -0
- package/dist/utils/authIdentity.d.cts +34 -0
- package/dist/utils/authIdentity.d.ts +34 -0
- package/dist/utils/authIdentity.js +50 -0
- package/dist/utils/failover.cjs +22 -0
- package/dist/utils/failover.d.cts +16 -0
- package/dist/utils/failover.d.ts +16 -0
- package/dist/utils/failover.js +20 -0
- package/dist/utils/handleRPCResponse.cjs +30 -0
- package/dist/utils/handleRPCResponse.js +28 -0
- package/dist/utils/index.cjs +55 -0
- package/dist/utils/index.d.cts +13 -0
- package/dist/utils/index.d.ts +13 -0
- package/dist/utils/index.js +50 -0
- package/dist/utils/messageFactory.cjs +137 -0
- package/dist/utils/messageFactory.d.cts +70 -0
- package/dist/utils/messageFactory.d.ts +70 -0
- package/dist/utils/messageFactory.js +132 -0
- package/dist/utils/multiPayload/webauthn.cjs +27 -0
- package/dist/utils/multiPayload/webauthn.js +26 -0
- package/dist/utils/near.cjs +58 -0
- package/dist/utils/near.d.cts +35 -0
- package/dist/utils/near.d.ts +35 -0
- package/dist/utils/near.js +53 -0
- package/dist/utils/poll.cjs +87 -0
- package/dist/utils/poll.d.cts +54 -0
- package/dist/utils/poll.d.ts +54 -0
- package/dist/utils/poll.js +85 -0
- package/dist/utils/prepareBroadcastRequest.cjs +98 -0
- package/dist/utils/prepareBroadcastRequest.d.cts +16 -0
- package/dist/utils/prepareBroadcastRequest.d.ts +16 -0
- package/dist/utils/prepareBroadcastRequest.js +90 -0
- package/dist/utils/promise/withTimeout.cjs +34 -0
- package/dist/utils/promise/withTimeout.d.cts +16 -0
- package/dist/utils/promise/withTimeout.d.ts +16 -0
- package/dist/utils/promise/withTimeout.js +34 -0
- package/dist/utils/request.cjs +100 -0
- package/dist/utils/request.d.cts +27 -0
- package/dist/utils/request.d.ts +27 -0
- package/dist/utils/request.js +99 -0
- package/dist/utils/requestShouldRetry.cjs +20 -0
- package/dist/utils/requestShouldRetry.js +20 -0
- package/dist/utils/retry.cjs +66 -0
- package/dist/utils/retry.d.cts +56 -0
- package/dist/utils/retry.d.ts +56 -0
- package/dist/utils/retry.js +64 -0
- package/dist/utils/serialize.cjs +82 -0
- package/dist/utils/serialize.d.cts +17 -0
- package/dist/utils/serialize.d.ts +17 -0
- package/dist/utils/serialize.js +81 -0
- package/dist/utils/stellarAddressToBytes.cjs +295 -0
- package/dist/utils/stellarAddressToBytes.js +294 -0
- package/dist/utils/token.cjs +8 -0
- package/dist/utils/token.js +7 -0
- package/dist/utils/tokenUtils.cjs +263 -0
- package/dist/utils/tokenUtils.d.cts +88 -0
- package/dist/utils/tokenUtils.d.ts +88 -0
- package/dist/utils/tokenUtils.js +238 -0
- package/dist/utils/tronAddressToHex.cjs +18 -0
- package/dist/utils/tronAddressToHex.js +17 -0
- package/dist/utils/uint8Array.cjs +15 -0
- package/dist/utils/uint8Array.d.cts +4 -0
- package/dist/utils/uint8Array.d.ts +4 -0
- package/dist/utils/uint8Array.js +14 -0
- package/dist/utils/webAuthn.cjs +91 -0
- package/dist/utils/webAuthn.js +89 -0
- package/package.json +56 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let _scure_base = require("@scure/base");
|
|
3
|
+
|
|
4
|
+
//#region src/utils/tronAddressToHex.ts
|
|
5
|
+
const tronAddressToHex = (credential) => {
|
|
6
|
+
try {
|
|
7
|
+
const payload = _scure_base.base58.decode(credential);
|
|
8
|
+
if (payload.length < 21) throw new Error("Invalid Tron address: too short");
|
|
9
|
+
const addressBytes = payload.slice(0, 21);
|
|
10
|
+
if (addressBytes[0] !== 65) throw new Error("Invalid Tron address: wrong prefix");
|
|
11
|
+
return _scure_base.hex.encode(addressBytes);
|
|
12
|
+
} catch (_error) {
|
|
13
|
+
throw new Error("Invalid Tron address");
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
exports.tronAddressToHex = tronAddressToHex;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { base58, hex } from "@scure/base";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/tronAddressToHex.ts
|
|
4
|
+
const tronAddressToHex = (credential) => {
|
|
5
|
+
try {
|
|
6
|
+
const payload = base58.decode(credential);
|
|
7
|
+
if (payload.length < 21) throw new Error("Invalid Tron address: too short");
|
|
8
|
+
const addressBytes = payload.slice(0, 21);
|
|
9
|
+
if (addressBytes[0] !== 65) throw new Error("Invalid Tron address: wrong prefix");
|
|
10
|
+
return hex.encode(addressBytes);
|
|
11
|
+
} catch (_error) {
|
|
12
|
+
throw new Error("Invalid Tron address");
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { tronAddressToHex };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/utils/uint8Array.ts
|
|
3
|
+
function concatUint8Arrays(arrays) {
|
|
4
|
+
let pointer = 0;
|
|
5
|
+
const totalLength = arrays.reduce((prev, curr) => prev + curr.length, 0);
|
|
6
|
+
const toReturn = new Uint8Array(totalLength);
|
|
7
|
+
for (const arr of arrays) {
|
|
8
|
+
toReturn.set(arr, pointer);
|
|
9
|
+
pointer += arr.length;
|
|
10
|
+
}
|
|
11
|
+
return toReturn;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
exports.concatUint8Arrays = concatUint8Arrays;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/utils/uint8Array.ts
|
|
2
|
+
function concatUint8Arrays(arrays) {
|
|
3
|
+
let pointer = 0;
|
|
4
|
+
const totalLength = arrays.reduce((prev, curr) => prev + curr.length, 0);
|
|
5
|
+
const toReturn = new Uint8Array(totalLength);
|
|
6
|
+
for (const arr of arrays) {
|
|
7
|
+
toReturn.set(arr, pointer);
|
|
8
|
+
pointer += arr.length;
|
|
9
|
+
}
|
|
10
|
+
return toReturn;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
export { concatUint8Arrays };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_uint8Array = require('./uint8Array.cjs');
|
|
3
|
+
let _scure_base = require("@scure/base");
|
|
4
|
+
let _peculiar_asn1_ecc = require("@peculiar/asn1-ecc");
|
|
5
|
+
let _peculiar_asn1_schema = require("@peculiar/asn1-schema");
|
|
6
|
+
require("tweetnacl");
|
|
7
|
+
|
|
8
|
+
//#region src/utils/webAuthn.ts
|
|
9
|
+
function parsePublicKey(formattedPublicKey) {
|
|
10
|
+
const curveType = getCurveType(formattedPublicKey);
|
|
11
|
+
switch (curveType) {
|
|
12
|
+
case "p256": {
|
|
13
|
+
let publicKey;
|
|
14
|
+
try {
|
|
15
|
+
publicKey = _scure_base.base58.decode(formattedPublicKey.slice(5));
|
|
16
|
+
} catch (err) {
|
|
17
|
+
throw new Error("Public key is not base58 encoded", { cause: err });
|
|
18
|
+
}
|
|
19
|
+
if (publicKey.length !== 64) throw new Error(`Invalid public key size for P-256 curve, it must be 64 bytes, but got ${publicKey.length} bytes`);
|
|
20
|
+
return {
|
|
21
|
+
curveType,
|
|
22
|
+
publicKey
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
case "ed25519": {
|
|
26
|
+
let publicKey;
|
|
27
|
+
try {
|
|
28
|
+
publicKey = _scure_base.base58.decode(formattedPublicKey.slice(8));
|
|
29
|
+
} catch (err) {
|
|
30
|
+
throw new Error("Public key is not base58 encoded", { cause: err });
|
|
31
|
+
}
|
|
32
|
+
if (publicKey.length !== 32) throw new Error(`Invalid public key size for Ed25519 curve, it must be 32 bytes, but got ${publicKey.length} bytes`);
|
|
33
|
+
return {
|
|
34
|
+
curveType,
|
|
35
|
+
publicKey
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
default: throw new Error(`Unsupported curve type ${curveType}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function getCurveType(formattedPublicKey) {
|
|
42
|
+
const delim = formattedPublicKey.indexOf(":");
|
|
43
|
+
if (delim === -1) throw new Error("Invalid public key format");
|
|
44
|
+
return formattedPublicKey.slice(0, delim);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Gets the actual signature from AuthenticatorAssertionResponse#signature bytes
|
|
48
|
+
*/
|
|
49
|
+
function extractRawSignature(attestationSignature_, curveType) {
|
|
50
|
+
const attestationSignature = new Uint8Array(attestationSignature_);
|
|
51
|
+
switch (curveType) {
|
|
52
|
+
case "ed25519": return attestationSignature;
|
|
53
|
+
case "p256": {
|
|
54
|
+
const parsedSignature = _peculiar_asn1_schema.AsnParser.parse(attestationSignature, _peculiar_asn1_ecc.ECDSASigValue);
|
|
55
|
+
let rBytes = new Uint8Array(parsedSignature.r);
|
|
56
|
+
let sBytes = new Uint8Array(parsedSignature.s);
|
|
57
|
+
if (shouldRemoveLeadingZero(rBytes)) rBytes = rBytes.slice(1);
|
|
58
|
+
if (shouldRemoveLeadingZero(sBytes)) sBytes = sBytes.slice(1);
|
|
59
|
+
sBytes = normalizeSignatureS(sBytes);
|
|
60
|
+
return require_uint8Array.concatUint8Arrays([rBytes, sBytes]);
|
|
61
|
+
}
|
|
62
|
+
default: throw new Error(`Unsupported curve type ${curveType}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Specific for DER encoding of ECDSA signature.
|
|
67
|
+
* Shouldn't be used for other purposes.
|
|
68
|
+
*/
|
|
69
|
+
function shouldRemoveLeadingZero(bytes) {
|
|
70
|
+
return bytes[0] === 0 && (bytes[1] & 128) !== 0;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Ensures the signature's s-value is in the lower half of the curve order
|
|
74
|
+
* to prevent signature malleability.
|
|
75
|
+
* See: https://github.com/kadenzipfel/smart-contract-vulnerabilities/blob/master/vulnerabilities/signature-malleability.md
|
|
76
|
+
*/
|
|
77
|
+
function normalizeSignatureS(sBytes) {
|
|
78
|
+
const P256_N = BigInt("0xFFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551");
|
|
79
|
+
const P256_N_HALF = P256_N >> 1n;
|
|
80
|
+
const sHex = _scure_base.hex.encode(sBytes);
|
|
81
|
+
const s = BigInt(`0x${sHex}`);
|
|
82
|
+
if (s > P256_N_HALF) {
|
|
83
|
+
const sLow = P256_N - s;
|
|
84
|
+
return _scure_base.hex.decode(sLow.toString(16).padStart(64, "0"));
|
|
85
|
+
}
|
|
86
|
+
return sBytes;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
exports.extractRawSignature = extractRawSignature;
|
|
91
|
+
exports.parsePublicKey = parsePublicKey;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { concatUint8Arrays } from "./uint8Array.js";
|
|
2
|
+
import { base58, base64urlnopad, hex } from "@scure/base";
|
|
3
|
+
import { ECDSASigValue } from "@peculiar/asn1-ecc";
|
|
4
|
+
import { AsnParser } from "@peculiar/asn1-schema";
|
|
5
|
+
import "tweetnacl";
|
|
6
|
+
|
|
7
|
+
//#region src/utils/webAuthn.ts
|
|
8
|
+
function parsePublicKey(formattedPublicKey) {
|
|
9
|
+
const curveType = getCurveType(formattedPublicKey);
|
|
10
|
+
switch (curveType) {
|
|
11
|
+
case "p256": {
|
|
12
|
+
let publicKey;
|
|
13
|
+
try {
|
|
14
|
+
publicKey = base58.decode(formattedPublicKey.slice(5));
|
|
15
|
+
} catch (err) {
|
|
16
|
+
throw new Error("Public key is not base58 encoded", { cause: err });
|
|
17
|
+
}
|
|
18
|
+
if (publicKey.length !== 64) throw new Error(`Invalid public key size for P-256 curve, it must be 64 bytes, but got ${publicKey.length} bytes`);
|
|
19
|
+
return {
|
|
20
|
+
curveType,
|
|
21
|
+
publicKey
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
case "ed25519": {
|
|
25
|
+
let publicKey;
|
|
26
|
+
try {
|
|
27
|
+
publicKey = base58.decode(formattedPublicKey.slice(8));
|
|
28
|
+
} catch (err) {
|
|
29
|
+
throw new Error("Public key is not base58 encoded", { cause: err });
|
|
30
|
+
}
|
|
31
|
+
if (publicKey.length !== 32) throw new Error(`Invalid public key size for Ed25519 curve, it must be 32 bytes, but got ${publicKey.length} bytes`);
|
|
32
|
+
return {
|
|
33
|
+
curveType,
|
|
34
|
+
publicKey
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
default: throw new Error(`Unsupported curve type ${curveType}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function getCurveType(formattedPublicKey) {
|
|
41
|
+
const delim = formattedPublicKey.indexOf(":");
|
|
42
|
+
if (delim === -1) throw new Error("Invalid public key format");
|
|
43
|
+
return formattedPublicKey.slice(0, delim);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Gets the actual signature from AuthenticatorAssertionResponse#signature bytes
|
|
47
|
+
*/
|
|
48
|
+
function extractRawSignature(attestationSignature_, curveType) {
|
|
49
|
+
const attestationSignature = new Uint8Array(attestationSignature_);
|
|
50
|
+
switch (curveType) {
|
|
51
|
+
case "ed25519": return attestationSignature;
|
|
52
|
+
case "p256": {
|
|
53
|
+
const parsedSignature = AsnParser.parse(attestationSignature, ECDSASigValue);
|
|
54
|
+
let rBytes = new Uint8Array(parsedSignature.r);
|
|
55
|
+
let sBytes = new Uint8Array(parsedSignature.s);
|
|
56
|
+
if (shouldRemoveLeadingZero(rBytes)) rBytes = rBytes.slice(1);
|
|
57
|
+
if (shouldRemoveLeadingZero(sBytes)) sBytes = sBytes.slice(1);
|
|
58
|
+
sBytes = normalizeSignatureS(sBytes);
|
|
59
|
+
return concatUint8Arrays([rBytes, sBytes]);
|
|
60
|
+
}
|
|
61
|
+
default: throw new Error(`Unsupported curve type ${curveType}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Specific for DER encoding of ECDSA signature.
|
|
66
|
+
* Shouldn't be used for other purposes.
|
|
67
|
+
*/
|
|
68
|
+
function shouldRemoveLeadingZero(bytes) {
|
|
69
|
+
return bytes[0] === 0 && (bytes[1] & 128) !== 0;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Ensures the signature's s-value is in the lower half of the curve order
|
|
73
|
+
* to prevent signature malleability.
|
|
74
|
+
* See: https://github.com/kadenzipfel/smart-contract-vulnerabilities/blob/master/vulnerabilities/signature-malleability.md
|
|
75
|
+
*/
|
|
76
|
+
function normalizeSignatureS(sBytes) {
|
|
77
|
+
const P256_N = BigInt("0xFFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551");
|
|
78
|
+
const P256_N_HALF = P256_N >> 1n;
|
|
79
|
+
const sHex = hex.encode(sBytes);
|
|
80
|
+
const s = BigInt(`0x${sHex}`);
|
|
81
|
+
if (s > P256_N_HALF) {
|
|
82
|
+
const sLow = P256_N - s;
|
|
83
|
+
return hex.decode(sLow.toString(16).padStart(64, "0"));
|
|
84
|
+
}
|
|
85
|
+
return sBytes;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
export { extractRawSignature, parsePublicKey };
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lampamazaza-new-internal-utils",
|
|
3
|
+
"version": "0.24.3",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/defuse-protocol/sdk-monorepo.git",
|
|
9
|
+
"directory": "packages/internal-utils"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/defuse-protocol/sdk-monorepo/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/defuse-protocol/sdk-monorepo/tree/main/packages/internal-utils#readme",
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"main": "./dist/index.cjs",
|
|
17
|
+
"module": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js",
|
|
23
|
+
"require": "./dist/index.cjs",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@lifeomic/attempt": "^3.0.0",
|
|
32
|
+
"@noble/hashes": "^1.7.1",
|
|
33
|
+
"@peculiar/asn1-ecc": "^2.0.0",
|
|
34
|
+
"@peculiar/asn1-schema": "^2.0.0",
|
|
35
|
+
"@scure/base": "^1.0.0",
|
|
36
|
+
"@thames/monads": "^0.7.0",
|
|
37
|
+
"near-api-js": "^4.0.0 || ^5.0.0",
|
|
38
|
+
"tweetnacl": "^1.0.0",
|
|
39
|
+
"valibot": "^1.0.0",
|
|
40
|
+
"viem": "^2.0.0",
|
|
41
|
+
"lampamazaza-new-contract-types": "0.6.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"msw": "^2.11.3",
|
|
45
|
+
"tsdown": "0.19.0",
|
|
46
|
+
"typescript": "^5.4.2"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsdown",
|
|
50
|
+
"dev": "tsdown --watch",
|
|
51
|
+
"lint": "biome check .",
|
|
52
|
+
"lint:fix": "biome check --write .",
|
|
53
|
+
"format": "biome format --write .",
|
|
54
|
+
"typecheck": "tsc --noEmit"
|
|
55
|
+
}
|
|
56
|
+
}
|