lampamazaza-new-intents-sdk 0.47.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/LICENSE +21 -0
- package/README.md +1083 -0
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/index.cjs +124 -0
- package/dist/index.d.cts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +19 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-constants.cjs +10 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-constants.js +7 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-utils.cjs +44 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-utils.js +42 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.cjs +111 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.js +110 -0
- package/dist/src/bridges/direct-bridge/direct-bridge-constants.cjs +8 -0
- package/dist/src/bridges/direct-bridge/direct-bridge-constants.js +6 -0
- package/dist/src/bridges/direct-bridge/direct-bridge-utils.cjs +47 -0
- package/dist/src/bridges/direct-bridge/direct-bridge-utils.js +44 -0
- package/dist/src/bridges/direct-bridge/direct-bridge.cjs +155 -0
- package/dist/src/bridges/direct-bridge/direct-bridge.js +154 -0
- package/dist/src/bridges/direct-bridge/error.cjs +16 -0
- package/dist/src/bridges/direct-bridge/error.d.cts +12 -0
- package/dist/src/bridges/direct-bridge/error.d.ts +12 -0
- package/dist/src/bridges/direct-bridge/error.js +15 -0
- package/dist/src/bridges/hot-bridge/error.cjs +23 -0
- package/dist/src/bridges/hot-bridge/error.d.cts +19 -0
- package/dist/src/bridges/hot-bridge/error.d.ts +19 -0
- package/dist/src/bridges/hot-bridge/error.js +21 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-chains.cjs +21 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-chains.d.cts +6 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-chains.d.ts +6 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-chains.js +20 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-constants.cjs +11 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-constants.js +9 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-utils.cjs +66 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-utils.js +61 -0
- package/dist/src/bridges/hot-bridge/hot-bridge.cjs +241 -0
- package/dist/src/bridges/hot-bridge/hot-bridge.js +239 -0
- package/dist/src/bridges/intents-bridge/intents-bridge.cjs +59 -0
- package/dist/src/bridges/intents-bridge/intents-bridge.js +59 -0
- package/dist/src/bridges/omni-bridge/error.cjs +54 -0
- package/dist/src/bridges/omni-bridge/error.d.cts +41 -0
- package/dist/src/bridges/omni-bridge/error.d.ts +41 -0
- package/dist/src/bridges/omni-bridge/error.js +49 -0
- package/dist/src/bridges/omni-bridge/omni-bridge-constants.cjs +12 -0
- package/dist/src/bridges/omni-bridge/omni-bridge-constants.js +8 -0
- package/dist/src/bridges/omni-bridge/omni-bridge-utils.cjs +153 -0
- package/dist/src/bridges/omni-bridge/omni-bridge-utils.js +143 -0
- package/dist/src/bridges/omni-bridge/omni-bridge.cjs +316 -0
- package/dist/src/bridges/omni-bridge/omni-bridge.js +314 -0
- package/dist/src/bridges/poa-bridge/poa-bridge-utils.cjs +76 -0
- package/dist/src/bridges/poa-bridge/poa-bridge-utils.js +73 -0
- package/dist/src/bridges/poa-bridge/poa-bridge.cjs +175 -0
- package/dist/src/bridges/poa-bridge/poa-bridge.js +173 -0
- package/dist/src/bridges/poa-bridge/poa-constants.cjs +6 -0
- package/dist/src/bridges/poa-bridge/poa-constants.js +5 -0
- package/dist/src/classes/errors.cjs +87 -0
- package/dist/src/classes/errors.d.cts +48 -0
- package/dist/src/classes/errors.d.ts +48 -0
- package/dist/src/classes/errors.js +81 -0
- package/dist/src/constants/bridge-name-enum.cjs +11 -0
- package/dist/src/constants/bridge-name-enum.d.cts +11 -0
- package/dist/src/constants/bridge-name-enum.d.ts +11 -0
- package/dist/src/constants/bridge-name-enum.js +10 -0
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.cjs +17 -0
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.cts +12 -0
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.ts +12 -0
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.js +16 -0
- package/dist/src/constants/public-rpc-urls.cjs +25 -0
- package/dist/src/constants/public-rpc-urls.js +24 -0
- package/dist/src/constants/route-enum.cjs +13 -0
- package/dist/src/constants/route-enum.d.cts +13 -0
- package/dist/src/constants/route-enum.d.ts +13 -0
- package/dist/src/constants/route-enum.js +12 -0
- package/dist/src/constants/withdrawal-timing.cjs +68 -0
- package/dist/src/constants/withdrawal-timing.js +68 -0
- package/dist/src/core/withdrawal-watcher.cjs +86 -0
- package/dist/src/core/withdrawal-watcher.d.cts +18 -0
- package/dist/src/core/withdrawal-watcher.d.ts +19 -0
- package/dist/src/core/withdrawal-watcher.js +82 -0
- package/dist/src/intents/expirable-nonce.cjs +90 -0
- package/dist/src/intents/expirable-nonce.d.cts +44 -0
- package/dist/src/intents/expirable-nonce.d.ts +45 -0
- package/dist/src/intents/expirable-nonce.js +82 -0
- package/dist/src/intents/intent-executer-impl/intent-executer.cjs +85 -0
- package/dist/src/intents/intent-executer-impl/intent-executer.d.cts +20 -0
- package/dist/src/intents/intent-executer-impl/intent-executer.d.ts +24 -0
- package/dist/src/intents/intent-executer-impl/intent-executer.js +85 -0
- package/dist/src/intents/intent-hash.cjs +48 -0
- package/dist/src/intents/intent-hash.d.cts +8 -0
- package/dist/src/intents/intent-hash.d.ts +8 -0
- package/dist/src/intents/intent-hash.js +47 -0
- package/dist/src/intents/intent-hashes/erc191.cjs +38 -0
- package/dist/src/intents/intent-hashes/erc191.js +37 -0
- package/dist/src/intents/intent-hashes/nep413.cjs +23 -0
- package/dist/src/intents/intent-hashes/nep413.js +22 -0
- package/dist/src/intents/intent-hashes/raw-ed25519.cjs +26 -0
- package/dist/src/intents/intent-hashes/raw-ed25519.js +25 -0
- package/dist/src/intents/intent-hashes/sep53.cjs +36 -0
- package/dist/src/intents/intent-hashes/sep53.js +35 -0
- package/dist/src/intents/intent-hashes/tip191.cjs +39 -0
- package/dist/src/intents/intent-hashes/tip191.js +38 -0
- package/dist/src/intents/intent-hashes/ton-connect.cjs +105 -0
- package/dist/src/intents/intent-hashes/ton-connect.js +104 -0
- package/dist/src/intents/intent-hashes/webauthn.cjs +26 -0
- package/dist/src/intents/intent-hashes/webauthn.js +25 -0
- package/dist/src/intents/intent-payload-builder.cjs +208 -0
- package/dist/src/intents/intent-payload-builder.d.cts +161 -0
- package/dist/src/intents/intent-payload-builder.d.ts +161 -0
- package/dist/src/intents/intent-payload-builder.js +207 -0
- package/dist/src/intents/intent-payload-factory.cjs +23 -0
- package/dist/src/intents/intent-payload-factory.js +21 -0
- package/dist/src/intents/intent-relayer-impl/intent-relayer-public.cjs +43 -0
- package/dist/src/intents/intent-relayer-impl/intent-relayer-public.js +42 -0
- package/dist/src/intents/intent-signer-impl/factories.cjs +19 -0
- package/dist/src/intents/intent-signer-impl/factories.d.cts +11 -0
- package/dist/src/intents/intent-signer-impl/factories.d.ts +11 -0
- package/dist/src/intents/intent-signer-impl/factories.js +17 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.cjs +22 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.d.cts +15 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.d.ts +16 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.js +21 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-nep413.cjs +37 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-nep413.d.cts +14 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-nep413.d.ts +14 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-nep413.js +36 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-noop.cjs +8 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-noop.js +7 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-viem.cjs +31 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-viem.d.cts +17 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-viem.d.ts +17 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-viem.js +30 -0
- package/dist/src/intents/interfaces/intent-executer.d.ts +2 -0
- package/dist/src/intents/interfaces/intent-relayer.d.cts +43 -0
- package/dist/src/intents/interfaces/intent-relayer.d.ts +43 -0
- package/dist/src/intents/interfaces/intent-signer.d.cts +8 -0
- package/dist/src/intents/interfaces/intent-signer.d.ts +8 -0
- package/dist/src/intents/interfaces/salt-manager.d.cts +9 -0
- package/dist/src/intents/interfaces/salt-manager.d.ts +9 -0
- package/dist/src/intents/salt-manager.cjs +74 -0
- package/dist/src/intents/salt-manager.js +72 -0
- package/dist/src/intents/shared-types.d.cts +20 -0
- package/dist/src/intents/shared-types.d.ts +20 -0
- package/dist/src/lib/array.cjs +11 -0
- package/dist/src/lib/array.js +10 -0
- package/dist/src/lib/caip2.cjs +50 -0
- package/dist/src/lib/caip2.d.cts +38 -0
- package/dist/src/lib/caip2.d.ts +38 -0
- package/dist/src/lib/caip2.js +48 -0
- package/dist/src/lib/configure-rpc-config.cjs +20 -0
- package/dist/src/lib/configure-rpc-config.js +18 -0
- package/dist/src/lib/estimate-fee.cjs +96 -0
- package/dist/src/lib/estimate-fee.js +94 -0
- package/dist/src/lib/hex.cjs +11 -0
- package/dist/src/lib/hex.js +10 -0
- package/dist/src/lib/nep413.cjs +42 -0
- package/dist/src/lib/nep413.d.cts +14 -0
- package/dist/src/lib/nep413.d.ts +14 -0
- package/dist/src/lib/nep413.js +41 -0
- package/dist/src/lib/object.cjs +10 -0
- package/dist/src/lib/object.js +9 -0
- package/dist/src/lib/parse-defuse-asset-id.cjs +15 -0
- package/dist/src/lib/parse-defuse-asset-id.js +14 -0
- package/dist/src/lib/route-config-factory.cjs +43 -0
- package/dist/src/lib/route-config-factory.d.cts +13 -0
- package/dist/src/lib/route-config-factory.d.ts +13 -0
- package/dist/src/lib/route-config-factory.js +37 -0
- package/dist/src/lib/tokensUsdPricesHttpClient/apis.cjs +17 -0
- package/dist/src/lib/tokensUsdPricesHttpClient/apis.js +16 -0
- package/dist/src/lib/validateAddress.cjs +271 -0
- package/dist/src/lib/validateAddress.d.cts +14 -0
- package/dist/src/lib/validateAddress.d.ts +14 -0
- package/dist/src/lib/validateAddress.js +270 -0
- package/dist/src/sdk.cjs +435 -0
- package/dist/src/sdk.d.cts +231 -0
- package/dist/src/sdk.d.ts +231 -0
- package/dist/src/sdk.js +433 -0
- package/dist/src/shared-types.d.cts +378 -0
- package/dist/src/shared-types.d.ts +378 -0
- package/package.json +62 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let _noble_hashes_sha3 = require("@noble/hashes/sha3");
|
|
3
|
+
|
|
4
|
+
//#region src/intents/intent-hashes/erc191.ts
|
|
5
|
+
/**
|
|
6
|
+
* Compute the prehash for ERC-191 payload
|
|
7
|
+
* Format: "\x19Ethereum Signed Message:\n" + length + message
|
|
8
|
+
*/
|
|
9
|
+
function computeErc191Prehash(payload) {
|
|
10
|
+
const data = new TextEncoder().encode(payload);
|
|
11
|
+
const prefix = new TextEncoder().encode(`\x19Ethereum Signed Message:\n${data.length}`);
|
|
12
|
+
const result = new Uint8Array(prefix.length + data.length);
|
|
13
|
+
result.set(prefix, 0);
|
|
14
|
+
result.set(data, prefix.length);
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Compute the Keccak256 hash of an ERC-191 payload
|
|
19
|
+
* This is the hash that should be signed
|
|
20
|
+
*
|
|
21
|
+
* @param payload - The message string to hash
|
|
22
|
+
* @returns 32-byte hash as Uint8Array
|
|
23
|
+
*/
|
|
24
|
+
function computeErc191Hash(payload) {
|
|
25
|
+
return (0, _noble_hashes_sha3.keccak_256)(computeErc191Prehash(payload));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Compute hash from a signed ERC-191 payload
|
|
29
|
+
*
|
|
30
|
+
* @param signedPayload - The signed ERC-191 payload
|
|
31
|
+
* @returns 32-byte hash as Uint8Array
|
|
32
|
+
*/
|
|
33
|
+
function computeSignedErc191Hash(signedPayload) {
|
|
34
|
+
return computeErc191Hash(signedPayload.payload);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.computeSignedErc191Hash = computeSignedErc191Hash;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { keccak_256 } from "@noble/hashes/sha3";
|
|
2
|
+
|
|
3
|
+
//#region src/intents/intent-hashes/erc191.ts
|
|
4
|
+
/**
|
|
5
|
+
* Compute the prehash for ERC-191 payload
|
|
6
|
+
* Format: "\x19Ethereum Signed Message:\n" + length + message
|
|
7
|
+
*/
|
|
8
|
+
function computeErc191Prehash(payload) {
|
|
9
|
+
const data = new TextEncoder().encode(payload);
|
|
10
|
+
const prefix = new TextEncoder().encode(`\x19Ethereum Signed Message:\n${data.length}`);
|
|
11
|
+
const result = new Uint8Array(prefix.length + data.length);
|
|
12
|
+
result.set(prefix, 0);
|
|
13
|
+
result.set(data, prefix.length);
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Compute the Keccak256 hash of an ERC-191 payload
|
|
18
|
+
* This is the hash that should be signed
|
|
19
|
+
*
|
|
20
|
+
* @param payload - The message string to hash
|
|
21
|
+
* @returns 32-byte hash as Uint8Array
|
|
22
|
+
*/
|
|
23
|
+
function computeErc191Hash(payload) {
|
|
24
|
+
return keccak_256(computeErc191Prehash(payload));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Compute hash from a signed ERC-191 payload
|
|
28
|
+
*
|
|
29
|
+
* @param signedPayload - The signed ERC-191 payload
|
|
30
|
+
* @returns 32-byte hash as Uint8Array
|
|
31
|
+
*/
|
|
32
|
+
function computeSignedErc191Hash(signedPayload) {
|
|
33
|
+
return computeErc191Hash(signedPayload.payload);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { computeSignedErc191Hash };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_nep413 = require('../../lib/nep413.cjs');
|
|
3
|
+
let _scure_base = require("@scure/base");
|
|
4
|
+
|
|
5
|
+
//#region src/intents/intent-hashes/nep413.ts
|
|
6
|
+
/**
|
|
7
|
+
* Compute hash from a signed NEP-413 payload
|
|
8
|
+
*
|
|
9
|
+
* @param signed - The signed NEP-413 payload
|
|
10
|
+
* @returns 32-byte hash as Uint8Array
|
|
11
|
+
*/
|
|
12
|
+
async function computeSignedNep413Hash(signed) {
|
|
13
|
+
const payload = signed.payload;
|
|
14
|
+
return require_nep413.hashNEP413Message({
|
|
15
|
+
message: payload.message,
|
|
16
|
+
recipient: payload.recipient,
|
|
17
|
+
nonce: Array.from(_scure_base.base64.decode(payload.nonce)),
|
|
18
|
+
callback_url: payload.callbackUrl
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.computeSignedNep413Hash = computeSignedNep413Hash;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { hashNEP413Message } from "../../lib/nep413.js";
|
|
2
|
+
import { base64 } from "@scure/base";
|
|
3
|
+
|
|
4
|
+
//#region src/intents/intent-hashes/nep413.ts
|
|
5
|
+
/**
|
|
6
|
+
* Compute hash from a signed NEP-413 payload
|
|
7
|
+
*
|
|
8
|
+
* @param signed - The signed NEP-413 payload
|
|
9
|
+
* @returns 32-byte hash as Uint8Array
|
|
10
|
+
*/
|
|
11
|
+
async function computeSignedNep413Hash(signed) {
|
|
12
|
+
const payload = signed.payload;
|
|
13
|
+
return hashNEP413Message({
|
|
14
|
+
message: payload.message,
|
|
15
|
+
recipient: payload.recipient,
|
|
16
|
+
nonce: Array.from(base64.decode(payload.nonce)),
|
|
17
|
+
callback_url: payload.callbackUrl
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { computeSignedNep413Hash };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let _noble_hashes_sha2 = require("@noble/hashes/sha2");
|
|
3
|
+
|
|
4
|
+
//#region src/intents/intent-hashes/raw-ed25519.ts
|
|
5
|
+
/**
|
|
6
|
+
* Compute the SHA-256 hash of a Raw Ed25519 payload
|
|
7
|
+
* This simply hashes the UTF-8 encoded payload string
|
|
8
|
+
*
|
|
9
|
+
* @param payload - The message string to hash
|
|
10
|
+
* @returns 32-byte hash as Uint8Array
|
|
11
|
+
*/
|
|
12
|
+
function computeRawEd25519Hash(payload) {
|
|
13
|
+
return (0, _noble_hashes_sha2.sha256)(new TextEncoder().encode(payload));
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Compute hash from a signed Raw Ed25519 payload
|
|
17
|
+
*
|
|
18
|
+
* @param signedPayload - The signed Raw Ed25519 payload
|
|
19
|
+
* @returns 32-byte hash as Uint8Array
|
|
20
|
+
*/
|
|
21
|
+
function computeSignedRawEd25519Hash(signedPayload) {
|
|
22
|
+
return computeRawEd25519Hash(signedPayload.payload);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.computeSignedRawEd25519Hash = computeSignedRawEd25519Hash;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { sha256 } from "@noble/hashes/sha2";
|
|
2
|
+
|
|
3
|
+
//#region src/intents/intent-hashes/raw-ed25519.ts
|
|
4
|
+
/**
|
|
5
|
+
* Compute the SHA-256 hash of a Raw Ed25519 payload
|
|
6
|
+
* This simply hashes the UTF-8 encoded payload string
|
|
7
|
+
*
|
|
8
|
+
* @param payload - The message string to hash
|
|
9
|
+
* @returns 32-byte hash as Uint8Array
|
|
10
|
+
*/
|
|
11
|
+
function computeRawEd25519Hash(payload) {
|
|
12
|
+
return sha256(new TextEncoder().encode(payload));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Compute hash from a signed Raw Ed25519 payload
|
|
16
|
+
*
|
|
17
|
+
* @param signedPayload - The signed Raw Ed25519 payload
|
|
18
|
+
* @returns 32-byte hash as Uint8Array
|
|
19
|
+
*/
|
|
20
|
+
function computeSignedRawEd25519Hash(signedPayload) {
|
|
21
|
+
return computeRawEd25519Hash(signedPayload.payload);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { computeSignedRawEd25519Hash };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let lampamazaza_internal_utils = require("lampamazaza-internal-utils");
|
|
3
|
+
let _noble_hashes_sha2 = require("@noble/hashes/sha2");
|
|
4
|
+
|
|
5
|
+
//#region src/intents/intent-hashes/sep53.ts
|
|
6
|
+
/**
|
|
7
|
+
* Compute the prehash for SEP-53 payload
|
|
8
|
+
* Format: "Stellar Signed Message:\n" + message
|
|
9
|
+
*/
|
|
10
|
+
function computeSep53Prehash(payload) {
|
|
11
|
+
const prefix = new TextEncoder().encode("Stellar Signed Message:\n");
|
|
12
|
+
const data = new TextEncoder().encode(payload);
|
|
13
|
+
return lampamazaza_internal_utils.utils.concatUint8Arrays([prefix, data]);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Compute the SHA-256 hash of a SEP-53 payload
|
|
17
|
+
* This is the hash that should be signed
|
|
18
|
+
*
|
|
19
|
+
* @param payload - The message string to hash
|
|
20
|
+
* @returns 32-byte hash as Uint8Array
|
|
21
|
+
*/
|
|
22
|
+
function computeSep53Hash(payload) {
|
|
23
|
+
return (0, _noble_hashes_sha2.sha256)(computeSep53Prehash(payload));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Compute hash from a signed SEP-53 payload
|
|
27
|
+
*
|
|
28
|
+
* @param signedPayload - The signed SEP-53 payload
|
|
29
|
+
* @returns 32-byte hash as Uint8Array
|
|
30
|
+
*/
|
|
31
|
+
function computeSignedSep53Hash(signedPayload) {
|
|
32
|
+
return computeSep53Hash(signedPayload.payload);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
exports.computeSignedSep53Hash = computeSignedSep53Hash;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { utils } from "lampamazaza-internal-utils";
|
|
2
|
+
import { sha256 } from "@noble/hashes/sha2";
|
|
3
|
+
|
|
4
|
+
//#region src/intents/intent-hashes/sep53.ts
|
|
5
|
+
/**
|
|
6
|
+
* Compute the prehash for SEP-53 payload
|
|
7
|
+
* Format: "Stellar Signed Message:\n" + message
|
|
8
|
+
*/
|
|
9
|
+
function computeSep53Prehash(payload) {
|
|
10
|
+
const prefix = new TextEncoder().encode("Stellar Signed Message:\n");
|
|
11
|
+
const data = new TextEncoder().encode(payload);
|
|
12
|
+
return utils.concatUint8Arrays([prefix, data]);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Compute the SHA-256 hash of a SEP-53 payload
|
|
16
|
+
* This is the hash that should be signed
|
|
17
|
+
*
|
|
18
|
+
* @param payload - The message string to hash
|
|
19
|
+
* @returns 32-byte hash as Uint8Array
|
|
20
|
+
*/
|
|
21
|
+
function computeSep53Hash(payload) {
|
|
22
|
+
return sha256(computeSep53Prehash(payload));
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Compute hash from a signed SEP-53 payload
|
|
26
|
+
*
|
|
27
|
+
* @param signedPayload - The signed SEP-53 payload
|
|
28
|
+
* @returns 32-byte hash as Uint8Array
|
|
29
|
+
*/
|
|
30
|
+
function computeSignedSep53Hash(signedPayload) {
|
|
31
|
+
return computeSep53Hash(signedPayload.payload);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { computeSignedSep53Hash };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let _noble_hashes_sha3 = require("@noble/hashes/sha3");
|
|
3
|
+
|
|
4
|
+
//#region src/intents/intent-hashes/tip191.ts
|
|
5
|
+
/**
|
|
6
|
+
* Compute the prehash for TIP-191 payload
|
|
7
|
+
* Format: "\x19TRON Signed Message:\n" + length + message
|
|
8
|
+
* Note: Prefix from https://tronweb.network/docu/docs/Sign%20and%20Verify%20Message/
|
|
9
|
+
*/
|
|
10
|
+
function computeTip191Prehash(payload) {
|
|
11
|
+
const data = new TextEncoder().encode(payload);
|
|
12
|
+
const prefix = new TextEncoder().encode(`\x19TRON Signed Message:\n${data.length}`);
|
|
13
|
+
const result = new Uint8Array(prefix.length + data.length);
|
|
14
|
+
result.set(prefix, 0);
|
|
15
|
+
result.set(data, prefix.length);
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Compute the Keccak256 hash of a TIP-191 payload
|
|
20
|
+
* This is the hash that should be signed
|
|
21
|
+
*
|
|
22
|
+
* @param payload - The message string to hash
|
|
23
|
+
* @returns 32-byte hash as Uint8Array
|
|
24
|
+
*/
|
|
25
|
+
function computeTip191Hash(payload) {
|
|
26
|
+
return (0, _noble_hashes_sha3.keccak_256)(computeTip191Prehash(payload));
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Compute hash from a signed TIP-191 payload
|
|
30
|
+
*
|
|
31
|
+
* @param signedPayload - The signed TIP-191 payload
|
|
32
|
+
* @returns 32-byte hash as Uint8Array
|
|
33
|
+
*/
|
|
34
|
+
function computeSignedTip191Hash(signedPayload) {
|
|
35
|
+
return computeTip191Hash(signedPayload.payload);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
exports.computeSignedTip191Hash = computeSignedTip191Hash;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { keccak_256 } from "@noble/hashes/sha3";
|
|
2
|
+
|
|
3
|
+
//#region src/intents/intent-hashes/tip191.ts
|
|
4
|
+
/**
|
|
5
|
+
* Compute the prehash for TIP-191 payload
|
|
6
|
+
* Format: "\x19TRON Signed Message:\n" + length + message
|
|
7
|
+
* Note: Prefix from https://tronweb.network/docu/docs/Sign%20and%20Verify%20Message/
|
|
8
|
+
*/
|
|
9
|
+
function computeTip191Prehash(payload) {
|
|
10
|
+
const data = new TextEncoder().encode(payload);
|
|
11
|
+
const prefix = new TextEncoder().encode(`\x19TRON Signed Message:\n${data.length}`);
|
|
12
|
+
const result = new Uint8Array(prefix.length + data.length);
|
|
13
|
+
result.set(prefix, 0);
|
|
14
|
+
result.set(data, prefix.length);
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Compute the Keccak256 hash of a TIP-191 payload
|
|
19
|
+
* This is the hash that should be signed
|
|
20
|
+
*
|
|
21
|
+
* @param payload - The message string to hash
|
|
22
|
+
* @returns 32-byte hash as Uint8Array
|
|
23
|
+
*/
|
|
24
|
+
function computeTip191Hash(payload) {
|
|
25
|
+
return keccak_256(computeTip191Prehash(payload));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Compute hash from a signed TIP-191 payload
|
|
29
|
+
*
|
|
30
|
+
* @param signedPayload - The signed TIP-191 payload
|
|
31
|
+
* @returns 32-byte hash as Uint8Array
|
|
32
|
+
*/
|
|
33
|
+
function computeSignedTip191Hash(signedPayload) {
|
|
34
|
+
return computeTip191Hash(signedPayload.payload);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { computeSignedTip191Hash };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let _noble_hashes_sha2 = require("@noble/hashes/sha2");
|
|
3
|
+
|
|
4
|
+
//#region src/intents/intent-hashes/ton-connect.ts
|
|
5
|
+
/**
|
|
6
|
+
* Convert number to big-endian byte array
|
|
7
|
+
*/
|
|
8
|
+
function numberToBigEndian(num, bytes) {
|
|
9
|
+
const result = new Uint8Array(bytes);
|
|
10
|
+
for (let i = bytes - 1; i >= 0; i--) {
|
|
11
|
+
result[i] = num & 255;
|
|
12
|
+
num >>= 8;
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Parse TON address string to TonAddress object
|
|
18
|
+
* Supports raw format: "workchain:address_hex"
|
|
19
|
+
* Example: "0:f4809e5ffac9dc42a6b1d94c5e74ad5fd86378de675c805f2274d0055cbc9378"
|
|
20
|
+
*
|
|
21
|
+
* @param addressString - TON address string in raw format
|
|
22
|
+
* @returns Parsed TonAddress object
|
|
23
|
+
*/
|
|
24
|
+
function parseTonAddress(addressString) {
|
|
25
|
+
const parts = addressString.split(":");
|
|
26
|
+
if (parts.length !== 2) throw new Error(`Invalid TON address format: ${addressString}. Expected "workchain:address_hex"`);
|
|
27
|
+
const workchainId = parseInt(parts[0], 10);
|
|
28
|
+
if (Number.isNaN(workchainId)) throw new Error(`Invalid workchain ID: ${parts[0]}`);
|
|
29
|
+
const addressHex = parts[1].startsWith("0x") ? parts[1].slice(2) : parts[1];
|
|
30
|
+
if (addressHex.length !== 64) throw new Error(`Invalid address length: expected 64 hex characters, got ${addressHex.length}`);
|
|
31
|
+
const address = new Uint8Array(32);
|
|
32
|
+
for (let i = 0; i < 32; i++) address[i] = parseInt(addressHex.slice(i * 2, i * 2 + 2), 16);
|
|
33
|
+
return {
|
|
34
|
+
workchainId,
|
|
35
|
+
address
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Compute the SHA-256 hash of a TON Connect payload
|
|
40
|
+
*
|
|
41
|
+
* For text and binary payloads:
|
|
42
|
+
* Hash = SHA256(
|
|
43
|
+
* 0xffff +
|
|
44
|
+
* "ton-connect/sign-data/" +
|
|
45
|
+
* workchain_id (4 bytes BE) +
|
|
46
|
+
* address (32 bytes) +
|
|
47
|
+
* domain_len (4 bytes BE) +
|
|
48
|
+
* domain +
|
|
49
|
+
* timestamp (8 bytes BE) +
|
|
50
|
+
* payload_type ("txt" or "bin") +
|
|
51
|
+
* payload_len (4 bytes BE) +
|
|
52
|
+
* payload
|
|
53
|
+
* )
|
|
54
|
+
*
|
|
55
|
+
* For cell payloads: Uses TON TLB message serialization (not fully implemented here)
|
|
56
|
+
*
|
|
57
|
+
* @param payload - The TON Connect payload to hash
|
|
58
|
+
* @returns 32-byte hash as Uint8Array
|
|
59
|
+
*/
|
|
60
|
+
function computeTonConnectHash(payload) {
|
|
61
|
+
const { address, domain, timestamp, payload: payloadSchema } = payload;
|
|
62
|
+
const parsedAddress = parseTonAddress(address);
|
|
63
|
+
const schemaType = payloadSchema.type;
|
|
64
|
+
switch (schemaType) {
|
|
65
|
+
case "text": {
|
|
66
|
+
const payloadPrefix = "txt";
|
|
67
|
+
const payloadData = new TextEncoder().encode(payloadSchema.text);
|
|
68
|
+
const parts = [
|
|
69
|
+
new Uint8Array([255, 255]),
|
|
70
|
+
new TextEncoder().encode("ton-connect/sign-data/"),
|
|
71
|
+
numberToBigEndian(parsedAddress.workchainId, 4),
|
|
72
|
+
parsedAddress.address,
|
|
73
|
+
numberToBigEndian(domain.length, 4),
|
|
74
|
+
new TextEncoder().encode(domain),
|
|
75
|
+
numberToBigEndian(Number(timestamp), 8),
|
|
76
|
+
new TextEncoder().encode(payloadPrefix),
|
|
77
|
+
numberToBigEndian(payloadData.length, 4),
|
|
78
|
+
payloadData
|
|
79
|
+
];
|
|
80
|
+
const totalLength = parts.reduce((sum, part) => sum + part.length, 0);
|
|
81
|
+
const message = new Uint8Array(totalLength);
|
|
82
|
+
let offset = 0;
|
|
83
|
+
for (const part of parts) {
|
|
84
|
+
message.set(part, offset);
|
|
85
|
+
offset += part.length;
|
|
86
|
+
}
|
|
87
|
+
return (0, _noble_hashes_sha2.sha256)(message);
|
|
88
|
+
}
|
|
89
|
+
case "binary": throw new Error("Binary payload hashing is not yet supported");
|
|
90
|
+
case "cell": throw new Error("Cell payload hashing is not yet supported.");
|
|
91
|
+
default: throw new Error(`Unknown TON Connect payload type: ${schemaType}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Compute hash from a signed TON Connect payload
|
|
96
|
+
*
|
|
97
|
+
* @param signedPayload - The signed TON Connect payload
|
|
98
|
+
* @returns 32-byte hash as Uint8Array
|
|
99
|
+
*/
|
|
100
|
+
function computeSignedTonConnectHash(signedPayload) {
|
|
101
|
+
return computeTonConnectHash(signedPayload);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
//#endregion
|
|
105
|
+
exports.computeSignedTonConnectHash = computeSignedTonConnectHash;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { sha256 } from "@noble/hashes/sha2";
|
|
2
|
+
|
|
3
|
+
//#region src/intents/intent-hashes/ton-connect.ts
|
|
4
|
+
/**
|
|
5
|
+
* Convert number to big-endian byte array
|
|
6
|
+
*/
|
|
7
|
+
function numberToBigEndian(num, bytes) {
|
|
8
|
+
const result = new Uint8Array(bytes);
|
|
9
|
+
for (let i = bytes - 1; i >= 0; i--) {
|
|
10
|
+
result[i] = num & 255;
|
|
11
|
+
num >>= 8;
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Parse TON address string to TonAddress object
|
|
17
|
+
* Supports raw format: "workchain:address_hex"
|
|
18
|
+
* Example: "0:f4809e5ffac9dc42a6b1d94c5e74ad5fd86378de675c805f2274d0055cbc9378"
|
|
19
|
+
*
|
|
20
|
+
* @param addressString - TON address string in raw format
|
|
21
|
+
* @returns Parsed TonAddress object
|
|
22
|
+
*/
|
|
23
|
+
function parseTonAddress(addressString) {
|
|
24
|
+
const parts = addressString.split(":");
|
|
25
|
+
if (parts.length !== 2) throw new Error(`Invalid TON address format: ${addressString}. Expected "workchain:address_hex"`);
|
|
26
|
+
const workchainId = parseInt(parts[0], 10);
|
|
27
|
+
if (Number.isNaN(workchainId)) throw new Error(`Invalid workchain ID: ${parts[0]}`);
|
|
28
|
+
const addressHex = parts[1].startsWith("0x") ? parts[1].slice(2) : parts[1];
|
|
29
|
+
if (addressHex.length !== 64) throw new Error(`Invalid address length: expected 64 hex characters, got ${addressHex.length}`);
|
|
30
|
+
const address = new Uint8Array(32);
|
|
31
|
+
for (let i = 0; i < 32; i++) address[i] = parseInt(addressHex.slice(i * 2, i * 2 + 2), 16);
|
|
32
|
+
return {
|
|
33
|
+
workchainId,
|
|
34
|
+
address
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Compute the SHA-256 hash of a TON Connect payload
|
|
39
|
+
*
|
|
40
|
+
* For text and binary payloads:
|
|
41
|
+
* Hash = SHA256(
|
|
42
|
+
* 0xffff +
|
|
43
|
+
* "ton-connect/sign-data/" +
|
|
44
|
+
* workchain_id (4 bytes BE) +
|
|
45
|
+
* address (32 bytes) +
|
|
46
|
+
* domain_len (4 bytes BE) +
|
|
47
|
+
* domain +
|
|
48
|
+
* timestamp (8 bytes BE) +
|
|
49
|
+
* payload_type ("txt" or "bin") +
|
|
50
|
+
* payload_len (4 bytes BE) +
|
|
51
|
+
* payload
|
|
52
|
+
* )
|
|
53
|
+
*
|
|
54
|
+
* For cell payloads: Uses TON TLB message serialization (not fully implemented here)
|
|
55
|
+
*
|
|
56
|
+
* @param payload - The TON Connect payload to hash
|
|
57
|
+
* @returns 32-byte hash as Uint8Array
|
|
58
|
+
*/
|
|
59
|
+
function computeTonConnectHash(payload) {
|
|
60
|
+
const { address, domain, timestamp, payload: payloadSchema } = payload;
|
|
61
|
+
const parsedAddress = parseTonAddress(address);
|
|
62
|
+
const schemaType = payloadSchema.type;
|
|
63
|
+
switch (schemaType) {
|
|
64
|
+
case "text": {
|
|
65
|
+
const payloadPrefix = "txt";
|
|
66
|
+
const payloadData = new TextEncoder().encode(payloadSchema.text);
|
|
67
|
+
const parts = [
|
|
68
|
+
new Uint8Array([255, 255]),
|
|
69
|
+
new TextEncoder().encode("ton-connect/sign-data/"),
|
|
70
|
+
numberToBigEndian(parsedAddress.workchainId, 4),
|
|
71
|
+
parsedAddress.address,
|
|
72
|
+
numberToBigEndian(domain.length, 4),
|
|
73
|
+
new TextEncoder().encode(domain),
|
|
74
|
+
numberToBigEndian(Number(timestamp), 8),
|
|
75
|
+
new TextEncoder().encode(payloadPrefix),
|
|
76
|
+
numberToBigEndian(payloadData.length, 4),
|
|
77
|
+
payloadData
|
|
78
|
+
];
|
|
79
|
+
const totalLength = parts.reduce((sum, part) => sum + part.length, 0);
|
|
80
|
+
const message = new Uint8Array(totalLength);
|
|
81
|
+
let offset = 0;
|
|
82
|
+
for (const part of parts) {
|
|
83
|
+
message.set(part, offset);
|
|
84
|
+
offset += part.length;
|
|
85
|
+
}
|
|
86
|
+
return sha256(message);
|
|
87
|
+
}
|
|
88
|
+
case "binary": throw new Error("Binary payload hashing is not yet supported");
|
|
89
|
+
case "cell": throw new Error("Cell payload hashing is not yet supported.");
|
|
90
|
+
default: throw new Error(`Unknown TON Connect payload type: ${schemaType}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Compute hash from a signed TON Connect payload
|
|
95
|
+
*
|
|
96
|
+
* @param signedPayload - The signed TON Connect payload
|
|
97
|
+
* @returns 32-byte hash as Uint8Array
|
|
98
|
+
*/
|
|
99
|
+
function computeSignedTonConnectHash(signedPayload) {
|
|
100
|
+
return computeTonConnectHash(signedPayload);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
//#endregion
|
|
104
|
+
export { computeSignedTonConnectHash };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let _noble_hashes_sha2 = require("@noble/hashes/sha2");
|
|
3
|
+
|
|
4
|
+
//#region src/intents/intent-hashes/webauthn.ts
|
|
5
|
+
/**
|
|
6
|
+
* Compute the SHA-256 hash of a WebAuthn payload
|
|
7
|
+
* This simply hashes the UTF-8 encoded payload string
|
|
8
|
+
*
|
|
9
|
+
* @param payload - The message string to hash
|
|
10
|
+
* @returns 32-byte hash as Uint8Array
|
|
11
|
+
*/
|
|
12
|
+
function computeWebAuthnHash(payload) {
|
|
13
|
+
return (0, _noble_hashes_sha2.sha256)(new TextEncoder().encode(payload));
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Compute hash from a signed WebAuthn payload
|
|
17
|
+
*
|
|
18
|
+
* @param signedPayload - The signed WebAuthn payload
|
|
19
|
+
* @returns 32-byte hash as Uint8Array
|
|
20
|
+
*/
|
|
21
|
+
function computeSignedWebAuthnHash(signedPayload) {
|
|
22
|
+
return computeWebAuthnHash(signedPayload.payload);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.computeSignedWebAuthnHash = computeSignedWebAuthnHash;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { sha256 } from "@noble/hashes/sha2";
|
|
2
|
+
|
|
3
|
+
//#region src/intents/intent-hashes/webauthn.ts
|
|
4
|
+
/**
|
|
5
|
+
* Compute the SHA-256 hash of a WebAuthn payload
|
|
6
|
+
* This simply hashes the UTF-8 encoded payload string
|
|
7
|
+
*
|
|
8
|
+
* @param payload - The message string to hash
|
|
9
|
+
* @returns 32-byte hash as Uint8Array
|
|
10
|
+
*/
|
|
11
|
+
function computeWebAuthnHash(payload) {
|
|
12
|
+
return sha256(new TextEncoder().encode(payload));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Compute hash from a signed WebAuthn payload
|
|
16
|
+
*
|
|
17
|
+
* @param signedPayload - The signed WebAuthn payload
|
|
18
|
+
* @returns 32-byte hash as Uint8Array
|
|
19
|
+
*/
|
|
20
|
+
function computeSignedWebAuthnHash(signedPayload) {
|
|
21
|
+
return computeWebAuthnHash(signedPayload.payload);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { computeSignedWebAuthnHash };
|