@qorechain/sdk 0.4.0 → 0.5.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 +201 -0
- package/README.md +180 -10
- package/dist/index.cjs +264 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +396 -17
- package/dist/index.d.ts +396 -17
- package/dist/index.js +228 -11
- package/dist/index.js.map +1 -1
- package/package.json +27 -13
package/dist/index.js
CHANGED
|
@@ -14,8 +14,9 @@ import { wordlist } from '@scure/bip39/wordlists/english';
|
|
|
14
14
|
import { HDKey as HDKey$1 } from '@scure/bip32';
|
|
15
15
|
import { HDKey } from 'micro-key-producer/slip10.js';
|
|
16
16
|
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
17
|
-
import {
|
|
17
|
+
import { mldsa87 } from '@qorechain/pqc';
|
|
18
18
|
import { randomBytes } from '@noble/hashes/utils';
|
|
19
|
+
export { AI_ANOMALY_CHECK_ADDRESS, AI_RISK_SCORE_ADDRESS, RISK_LEVEL_UNSAFE_THRESHOLD, ai, aiAnomalyCheck, aiRiskScore, simulateWithRiskScore } from '@qorechain/evm';
|
|
19
20
|
import { connectComet } from '@cosmjs/tendermint-rpc';
|
|
20
21
|
import { Any } from 'cosmjs-types/google/protobuf/any';
|
|
21
22
|
import { TxBody, SignDoc, TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
|
|
@@ -440,7 +441,7 @@ var QorClient = class extends JsonRpcClient {
|
|
|
440
441
|
// src/tx/fees.ts
|
|
441
442
|
var STATIC_FALLBACK = {
|
|
442
443
|
/** Fallback gas price, in base denom per unit of gas. */
|
|
443
|
-
gasPrice: "0.
|
|
444
|
+
gasPrice: "0.15",
|
|
444
445
|
/** Base denomination fees are paid in. */
|
|
445
446
|
denom: "uqor",
|
|
446
447
|
/** Default gas limit when the caller does not supply one. */
|
|
@@ -9713,7 +9714,7 @@ function calculateFee(gas, gasPrice) {
|
|
|
9713
9714
|
// src/tx/builder.ts
|
|
9714
9715
|
var MSG_SEND_TYPE_URL = "/cosmos.bank.v1beta1.MsgSend";
|
|
9715
9716
|
var DEFAULT_GAS_MULTIPLIER = 1.4;
|
|
9716
|
-
var DEFAULT_GAS_PRICE = "0.
|
|
9717
|
+
var DEFAULT_GAS_PRICE = "0.15uqor";
|
|
9717
9718
|
function buildAminoTypes(extra) {
|
|
9718
9719
|
return new AminoTypes({
|
|
9719
9720
|
...createDefaultAminoConverters(),
|
|
@@ -9792,7 +9793,7 @@ var TxClient = class _TxClient {
|
|
|
9792
9793
|
*
|
|
9793
9794
|
* `fee` may be an explicit {@link StdFee} or the literal `"auto"`, which
|
|
9794
9795
|
* simulates the tx to estimate gas and computes the fee from a gas
|
|
9795
|
-
* multiplier (default 1.4) and gas price (default `0.
|
|
9796
|
+
* multiplier (default 1.4) and gas price (default `0.15uqor`); tune both via
|
|
9796
9797
|
* `opts.autoFee`.
|
|
9797
9798
|
*
|
|
9798
9799
|
* Broadcast mode maps onto cosmjs transports:
|
|
@@ -10448,14 +10449,14 @@ function generatePqcKeypair(seed) {
|
|
|
10448
10449
|
);
|
|
10449
10450
|
}
|
|
10450
10451
|
const xi = seed ?? randomBytes(ML_DSA_87_SEED_LENGTH);
|
|
10451
|
-
const kp =
|
|
10452
|
+
const kp = mldsa87.keygen(xi);
|
|
10452
10453
|
return { publicKey: kp.publicKey, secretKey: kp.secretKey };
|
|
10453
10454
|
}
|
|
10454
|
-
function pqcSign(secretKey, message) {
|
|
10455
|
-
return
|
|
10455
|
+
function pqcSign(secretKey, message, opts) {
|
|
10456
|
+
return mldsa87.sign(secretKey, message, opts);
|
|
10456
10457
|
}
|
|
10457
10458
|
function pqcVerify(publicKey, message, signature) {
|
|
10458
|
-
return
|
|
10459
|
+
return mldsa87.verify(publicKey, message, signature);
|
|
10459
10460
|
}
|
|
10460
10461
|
function buildHybridSignatureExtension(args) {
|
|
10461
10462
|
const { algorithmId, signature, publicKey } = args;
|
|
@@ -19153,7 +19154,7 @@ function suggestChainInfo(network) {
|
|
|
19153
19154
|
};
|
|
19154
19155
|
const feeCurrency = {
|
|
19155
19156
|
...currency,
|
|
19156
|
-
gasPriceStep: { low: 0.
|
|
19157
|
+
gasPriceStep: { low: 0.1, average: 0.15, high: 0.25 }
|
|
19157
19158
|
};
|
|
19158
19159
|
return {
|
|
19159
19160
|
chainId,
|
|
@@ -19597,9 +19598,225 @@ function createRollupClient(tx, opts = {}) {
|
|
|
19597
19598
|
};
|
|
19598
19599
|
}
|
|
19599
19600
|
|
|
19601
|
+
// src/helpers/crossvm.ts
|
|
19602
|
+
var VM_TYPES = ["evm", "cosmwasm", "svm"];
|
|
19603
|
+
var HEX_RE = /^0x[0-9a-fA-F]*$/;
|
|
19604
|
+
function rawToBytes(data) {
|
|
19605
|
+
if (typeof data !== "string") return data;
|
|
19606
|
+
if (!HEX_RE.test(data)) {
|
|
19607
|
+
throw new Error(
|
|
19608
|
+
`crossvm: invalid hex payload (expected 0x-prefixed hex, got "${data.slice(0, 12)}...")`
|
|
19609
|
+
);
|
|
19610
|
+
}
|
|
19611
|
+
const hex = data.slice(2);
|
|
19612
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
19613
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
19614
|
+
bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
19615
|
+
}
|
|
19616
|
+
return bytes;
|
|
19617
|
+
}
|
|
19618
|
+
function cosmwasmToBytes(msg2) {
|
|
19619
|
+
return new TextEncoder().encode(JSON.stringify(msg2));
|
|
19620
|
+
}
|
|
19621
|
+
async function encodePayload(input) {
|
|
19622
|
+
if ("payload" in input) {
|
|
19623
|
+
return rawToBytes(input.payload);
|
|
19624
|
+
}
|
|
19625
|
+
if ("cosmwasm" in input) {
|
|
19626
|
+
return cosmwasmToBytes(input.cosmwasm);
|
|
19627
|
+
}
|
|
19628
|
+
if ("svm" in input) {
|
|
19629
|
+
return rawToBytes(input.svm.data);
|
|
19630
|
+
}
|
|
19631
|
+
const { encodeFunctionData } = await import('viem');
|
|
19632
|
+
const data = encodeFunctionData({
|
|
19633
|
+
// viem's Abi typing is structurally compatible; cast at the boundary.
|
|
19634
|
+
abi: input.evm.abi,
|
|
19635
|
+
functionName: input.evm.functionName,
|
|
19636
|
+
args: input.evm.args ?? []
|
|
19637
|
+
});
|
|
19638
|
+
return rawToBytes(data);
|
|
19639
|
+
}
|
|
19640
|
+
function requireGetMessageSource(query, qor) {
|
|
19641
|
+
if (!query && !qor) {
|
|
19642
|
+
throw new Error(
|
|
19643
|
+
"crossvm getMessage requires a query client or a qor client \u2014 pass { query } or { qor } to createCrossVMClient"
|
|
19644
|
+
);
|
|
19645
|
+
}
|
|
19646
|
+
}
|
|
19647
|
+
function extractMessageIds(result) {
|
|
19648
|
+
const events = result.events;
|
|
19649
|
+
const ids = [];
|
|
19650
|
+
if (Array.isArray(events)) {
|
|
19651
|
+
for (const ev of events) {
|
|
19652
|
+
const attrs = ev.attributes;
|
|
19653
|
+
if (!Array.isArray(attrs)) continue;
|
|
19654
|
+
for (const a of attrs) {
|
|
19655
|
+
const key = String(a.key ?? "");
|
|
19656
|
+
if (key === "message_id" || key === "messageId") {
|
|
19657
|
+
ids.push(String(a.value ?? ""));
|
|
19658
|
+
}
|
|
19659
|
+
}
|
|
19660
|
+
}
|
|
19661
|
+
}
|
|
19662
|
+
return ids;
|
|
19663
|
+
}
|
|
19664
|
+
function createCrossVMClient(tx, opts = {}) {
|
|
19665
|
+
const sender = tx.senderAddress;
|
|
19666
|
+
const query = opts.query;
|
|
19667
|
+
const qor = opts.qor;
|
|
19668
|
+
const buildFrom = (o, payload) => crossvm.crossVmCall({
|
|
19669
|
+
sender,
|
|
19670
|
+
sourceVm: o.sourceVm ?? "evm",
|
|
19671
|
+
targetVm: o.targetVm,
|
|
19672
|
+
targetContract: o.targetContract,
|
|
19673
|
+
payload,
|
|
19674
|
+
funds: o.funds ?? []
|
|
19675
|
+
});
|
|
19676
|
+
const buildCallSync = (o, payload) => buildFrom(o, payload);
|
|
19677
|
+
const buildCall = (o) => {
|
|
19678
|
+
if ("evm" in o) {
|
|
19679
|
+
throw new Error(
|
|
19680
|
+
"crossvm buildCall: EVM payloads are ABI-encoded asynchronously (viem). Use `call`/`callAtomic`, or pre-encode and pass `{ payload }`."
|
|
19681
|
+
);
|
|
19682
|
+
}
|
|
19683
|
+
let payload;
|
|
19684
|
+
if ("payload" in o) payload = rawToBytes(o.payload);
|
|
19685
|
+
else if ("cosmwasm" in o) payload = cosmwasmToBytes(o.cosmwasm);
|
|
19686
|
+
else payload = rawToBytes(o.svm.data);
|
|
19687
|
+
return buildCallSync(o, payload);
|
|
19688
|
+
};
|
|
19689
|
+
const call = async (o) => {
|
|
19690
|
+
const payload = await encodePayload(o);
|
|
19691
|
+
const message = buildFrom(o, payload);
|
|
19692
|
+
const result = await tx.signAndBroadcast(
|
|
19693
|
+
[message],
|
|
19694
|
+
o.fee ?? "auto",
|
|
19695
|
+
o.memo ?? "",
|
|
19696
|
+
{ autoFee: o.autoFee }
|
|
19697
|
+
);
|
|
19698
|
+
const [messageId = ""] = extractMessageIds(result);
|
|
19699
|
+
return { messageId, result };
|
|
19700
|
+
};
|
|
19701
|
+
const callAtomic = async (calls, w = {}) => {
|
|
19702
|
+
if (calls.length === 0) {
|
|
19703
|
+
throw new Error("crossvm callAtomic: provide at least one call");
|
|
19704
|
+
}
|
|
19705
|
+
const messages = await Promise.all(
|
|
19706
|
+
calls.map(async (o) => buildFrom(o, await encodePayload(o)))
|
|
19707
|
+
);
|
|
19708
|
+
const result = await tx.signAndBroadcast(
|
|
19709
|
+
messages,
|
|
19710
|
+
w.fee ?? "auto",
|
|
19711
|
+
w.memo ?? "",
|
|
19712
|
+
{ autoFee: w.autoFee }
|
|
19713
|
+
);
|
|
19714
|
+
return { messageIds: extractMessageIds(result), result };
|
|
19715
|
+
};
|
|
19716
|
+
const getMessage = (id) => {
|
|
19717
|
+
requireGetMessageSource(query, qor);
|
|
19718
|
+
if (query) return query.message({ id });
|
|
19719
|
+
return qor.getCrossVmMessage(id);
|
|
19720
|
+
};
|
|
19721
|
+
return { call, buildCall, callAtomic, getMessage };
|
|
19722
|
+
}
|
|
19723
|
+
|
|
19724
|
+
// src/helpers/pqc.ts
|
|
19725
|
+
var PQC_KEY_STATUS_PRECOMPILE_ADDRESS = "0x0000000000000000000000000000000000000A02";
|
|
19726
|
+
function resolveQor(source) {
|
|
19727
|
+
if ("qor" in source && source.qor) return source.qor;
|
|
19728
|
+
return source;
|
|
19729
|
+
}
|
|
19730
|
+
function asBool(v) {
|
|
19731
|
+
if (typeof v === "boolean") return v;
|
|
19732
|
+
if (typeof v === "number") return v !== 0;
|
|
19733
|
+
if (typeof v === "string") return v === "true" || v === "1";
|
|
19734
|
+
return false;
|
|
19735
|
+
}
|
|
19736
|
+
function asNumber(v) {
|
|
19737
|
+
if (typeof v === "number") return v;
|
|
19738
|
+
if (typeof v === "string" && v.trim() !== "" && !Number.isNaN(Number(v))) {
|
|
19739
|
+
return Number(v);
|
|
19740
|
+
}
|
|
19741
|
+
return void 0;
|
|
19742
|
+
}
|
|
19743
|
+
async function getPqcStatus(source, address) {
|
|
19744
|
+
const qor = resolveQor(source);
|
|
19745
|
+
const raw = await qor.getPqcKeyStatus(address);
|
|
19746
|
+
if (raw == null || typeof raw !== "object") {
|
|
19747
|
+
return { registered: false };
|
|
19748
|
+
}
|
|
19749
|
+
const registered = asBool(
|
|
19750
|
+
raw.registered ?? raw.isRegistered ?? raw.is_registered
|
|
19751
|
+
);
|
|
19752
|
+
const algorithmId = asNumber(raw.algorithmId ?? raw.algorithm_id);
|
|
19753
|
+
const pubkeyRaw = raw.pubkey ?? raw.publicKey ?? raw.public_key;
|
|
19754
|
+
const pubkey = typeof pubkeyRaw === "string" || pubkeyRaw instanceof Uint8Array ? pubkeyRaw : void 0;
|
|
19755
|
+
const status = { registered };
|
|
19756
|
+
if (algorithmId !== void 0) status.algorithmId = algorithmId;
|
|
19757
|
+
if (pubkey !== void 0) status.pubkey = pubkey;
|
|
19758
|
+
return status;
|
|
19759
|
+
}
|
|
19760
|
+
async function isPqcRegistered(source, address) {
|
|
19761
|
+
const status = await getPqcStatus(source, address);
|
|
19762
|
+
return status.registered;
|
|
19763
|
+
}
|
|
19764
|
+
function buildRegisterPqcKeyMsg(sender, opts) {
|
|
19765
|
+
return pqc.registerPqcKeyV2({
|
|
19766
|
+
sender,
|
|
19767
|
+
publicKey: opts.pqcKeypair.publicKey,
|
|
19768
|
+
algorithmId: AlgorithmDilithium5,
|
|
19769
|
+
ecdsaPubkey: opts.ecdsaPubkey ?? new Uint8Array(0),
|
|
19770
|
+
keyType: opts.keyType ?? "hybrid"
|
|
19771
|
+
});
|
|
19772
|
+
}
|
|
19773
|
+
async function ensurePqcRegistered(tx, opts) {
|
|
19774
|
+
const sender = tx.senderAddress;
|
|
19775
|
+
const status = opts.status ?? (opts.statusSource ? await getPqcStatus(opts.statusSource, sender) : void 0);
|
|
19776
|
+
if (status?.registered) {
|
|
19777
|
+
return { alreadyRegistered: true };
|
|
19778
|
+
}
|
|
19779
|
+
const message = buildRegisterPqcKeyMsg(sender, opts);
|
|
19780
|
+
const result = await tx.signAndBroadcast(
|
|
19781
|
+
[message],
|
|
19782
|
+
opts.fee ?? "auto",
|
|
19783
|
+
opts.memo ?? "",
|
|
19784
|
+
{ autoFee: opts.autoFee }
|
|
19785
|
+
);
|
|
19786
|
+
return {
|
|
19787
|
+
alreadyRegistered: false,
|
|
19788
|
+
txHash: result.transactionHash,
|
|
19789
|
+
result
|
|
19790
|
+
};
|
|
19791
|
+
}
|
|
19792
|
+
async function migratePqcKey(tx, opts) {
|
|
19793
|
+
const message = pqc.migratePqcKey({
|
|
19794
|
+
sender: tx.senderAddress,
|
|
19795
|
+
oldPublicKey: opts.oldPublicKey,
|
|
19796
|
+
newPublicKey: opts.newPublicKey,
|
|
19797
|
+
newAlgorithmId: opts.newAlgorithmId ?? AlgorithmDilithium5,
|
|
19798
|
+
oldSignature: opts.oldSignature,
|
|
19799
|
+
newSignature: opts.newSignature
|
|
19800
|
+
});
|
|
19801
|
+
return tx.signAndBroadcast([message], opts.fee ?? "auto", opts.memo ?? "", {
|
|
19802
|
+
autoFee: opts.autoFee
|
|
19803
|
+
});
|
|
19804
|
+
}
|
|
19805
|
+
async function migrateToHybrid(tx, opts) {
|
|
19806
|
+
const ensured = await ensurePqcRegistered(tx, opts);
|
|
19807
|
+
const pqcKeypair = opts.pqcKeypair;
|
|
19808
|
+
return {
|
|
19809
|
+
alreadyRegistered: ensured.alreadyRegistered,
|
|
19810
|
+
registrationTxHash: ensured.txHash,
|
|
19811
|
+
pqcKeypair,
|
|
19812
|
+
buildHybridTx: (o) => buildHybridTx({ ...o, pqcKeypair }),
|
|
19813
|
+
signAndBroadcastHybrid: (o) => signAndBroadcastHybrid({ ...o, pqcKeypair })
|
|
19814
|
+
};
|
|
19815
|
+
}
|
|
19816
|
+
|
|
19600
19817
|
// src/index.ts
|
|
19601
|
-
var VERSION = "0.
|
|
19818
|
+
var VERSION = "0.5.0";
|
|
19602
19819
|
|
|
19603
|
-
export { AlgorithmDilithium5, AlgorithmMLKEM1024, AlgorithmUnspecified, DEFAULT_GAS_MULTIPLIER, DEFAULT_GAS_PRICE, GasPrice, HYBRID_SIG_TYPE_URL, HybridSigner, JsonRpcClient, JsonRpcError, ML_DSA_87_PUBLIC_KEY_LENGTH, ML_DSA_87_SECRET_KEY_LENGTH, ML_DSA_87_SEED_LENGTH, ML_DSA_87_SIGNATURE_LENGTH, MSG_SEND_TYPE_URL, NETWORKS, PqcSigner, QorClient, QoreHttpError, QoreTxError, RestClient, STATIC_FALLBACK, TxClient, VERSION, abstractaccount, algorithmName, amm, attachHybridExtension, authz, bank, bech32ToHex, bridge, broadcastAndWait, buildAminoTypes, buildEventsQuery, buildHybridSignatureExtension, buildHybridTx, buildTxQuery, buildUrl, bytesToBech32, calculateFee, clearAdmin, connectCosmWasmSigner, connectQueryClients, createClient, createCosmWasmClient, createMultilayerClient, createQueryClients, createRollupClient, createSubscriptionClient, crossvm, decodeTxError, deriveEvmAccount, deriveNativeAccount, deriveSvmAccount, directSignerFromPrivateKey, distribution, encodeHybridExtension, estimateFee, evmToQor, execute, explorerAddressUrl, explorerBlockUrl, explorerTxUrl, feegrant, formatUnits, fromBase, generateMnemonic, generatePqcKeypair, getBlock, getCodeDetails, getCodes, getContractInfo, getContracts, getCosmosWallet, getCrossVmMessage, getCrossVmParams, getJson, getLatestBlock, getNetwork, getPendingCrossVmMessages, getTx, gov, hexToBech32, ibc, instantiate, instantiate2, isChecksumAddress, isSignatureAlgorithm, isTxFailure, isValidBech32, isValidEvmAddress, isValidSvmAddress, joinUrl, keccak256, keccak256Hex, license, lightnode, listNetworks, migrate, msg, multilayer, parseUnits, postJsonRpc, pqc as pqcMsg, pqcSign, pqcVerify, qorToEvm, qorechainRegistry, qorechainRegistryTypes, codegen_exports as qorechainTypes, queryContractSmart, rdk, requestFaucet, ripemd160, ripemd160Hex, rlconsensus, searchTxs, sha256, sha256Hex, signAndBroadcastHybrid, staking, subscribeNewBlocks, subscribeTx, suggestChainInfo, svm, toBase, toChecksumAddress, toHex, txErrorFrom, updateAdmin, uploadCode, validateMnemonic, waitForTx, withRetry2 as withRetry };
|
|
19820
|
+
export { AlgorithmDilithium5, AlgorithmMLKEM1024, AlgorithmUnspecified, DEFAULT_GAS_MULTIPLIER, DEFAULT_GAS_PRICE, GasPrice, HYBRID_SIG_TYPE_URL, HybridSigner, JsonRpcClient, JsonRpcError, ML_DSA_87_PUBLIC_KEY_LENGTH, ML_DSA_87_SECRET_KEY_LENGTH, ML_DSA_87_SEED_LENGTH, ML_DSA_87_SIGNATURE_LENGTH, MSG_SEND_TYPE_URL, NETWORKS, PQC_KEY_STATUS_PRECOMPILE_ADDRESS, PqcSigner, QorClient, QoreHttpError, QoreTxError, RestClient, STATIC_FALLBACK, TxClient, VERSION, VM_TYPES, abstractaccount, algorithmName, amm, attachHybridExtension, authz, bank, bech32ToHex, bridge, broadcastAndWait, buildAminoTypes, buildEventsQuery, buildHybridSignatureExtension, buildHybridTx, buildRegisterPqcKeyMsg, buildTxQuery, buildUrl, bytesToBech32, calculateFee, clearAdmin, connectCosmWasmSigner, connectQueryClients, createClient, createCosmWasmClient, createCrossVMClient, createMultilayerClient, createQueryClients, createRollupClient, createSubscriptionClient, crossvm, decodeTxError, deriveEvmAccount, deriveNativeAccount, deriveSvmAccount, directSignerFromPrivateKey, distribution, encodeHybridExtension, ensurePqcRegistered, estimateFee, evmToQor, execute, explorerAddressUrl, explorerBlockUrl, explorerTxUrl, feegrant, formatUnits, fromBase, generateMnemonic, generatePqcKeypair, getBlock, getCodeDetails, getCodes, getContractInfo, getContracts, getCosmosWallet, getCrossVmMessage, getCrossVmParams, getJson, getLatestBlock, getNetwork, getPendingCrossVmMessages, getPqcStatus, getTx, gov, hexToBech32, ibc, instantiate, instantiate2, isChecksumAddress, isPqcRegistered, isSignatureAlgorithm, isTxFailure, isValidBech32, isValidEvmAddress, isValidSvmAddress, joinUrl, keccak256, keccak256Hex, license, lightnode, listNetworks, migrate, migratePqcKey, migrateToHybrid, msg, multilayer, parseUnits, postJsonRpc, pqc as pqcMsg, pqcSign, pqcVerify, qorToEvm, qorechainRegistry, qorechainRegistryTypes, codegen_exports as qorechainTypes, queryContractSmart, rdk, requestFaucet, ripemd160, ripemd160Hex, rlconsensus, searchTxs, sha256, sha256Hex, signAndBroadcastHybrid, staking, subscribeNewBlocks, subscribeTx, suggestChainInfo, svm, toBase, toChecksumAddress, toHex, txErrorFrom, updateAdmin, uploadCode, validateMnemonic, waitForTx, withRetry2 as withRetry };
|
|
19604
19821
|
//# sourceMappingURL=index.js.map
|
|
19605
19822
|
//# sourceMappingURL=index.js.map
|