@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/dist/index.cjs CHANGED
@@ -16,8 +16,9 @@ var english = require('@scure/bip39/wordlists/english');
16
16
  var bip32 = require('@scure/bip32');
17
17
  var slip10_js = require('micro-key-producer/slip10.js');
18
18
  var secp256k1 = require('@noble/curves/secp256k1');
19
- var mlDsa_js = require('@noble/post-quantum/ml-dsa.js');
19
+ var pqc$1 = require('@qorechain/pqc');
20
20
  var utils = require('@noble/hashes/utils');
21
+ var evm = require('@qorechain/evm');
21
22
  var tendermintRpc = require('@cosmjs/tendermint-rpc');
22
23
  var any = require('cosmjs-types/google/protobuf/any');
23
24
  var tx$1 = require('cosmjs-types/cosmos/tx/v1beta1/tx');
@@ -442,7 +443,7 @@ var QorClient = class extends JsonRpcClient {
442
443
  // src/tx/fees.ts
443
444
  var STATIC_FALLBACK = {
444
445
  /** Fallback gas price, in base denom per unit of gas. */
445
- gasPrice: "0.025",
446
+ gasPrice: "0.15",
446
447
  /** Base denomination fees are paid in. */
447
448
  denom: "uqor",
448
449
  /** Default gas limit when the caller does not supply one. */
@@ -9715,7 +9716,7 @@ function calculateFee(gas, gasPrice) {
9715
9716
  // src/tx/builder.ts
9716
9717
  var MSG_SEND_TYPE_URL = "/cosmos.bank.v1beta1.MsgSend";
9717
9718
  var DEFAULT_GAS_MULTIPLIER = 1.4;
9718
- var DEFAULT_GAS_PRICE = "0.025uqor";
9719
+ var DEFAULT_GAS_PRICE = "0.15uqor";
9719
9720
  function buildAminoTypes(extra) {
9720
9721
  return new stargate.AminoTypes({
9721
9722
  ...stargate.createDefaultAminoConverters(),
@@ -9794,7 +9795,7 @@ var TxClient = class _TxClient {
9794
9795
  *
9795
9796
  * `fee` may be an explicit {@link StdFee} or the literal `"auto"`, which
9796
9797
  * simulates the tx to estimate gas and computes the fee from a gas
9797
- * multiplier (default 1.4) and gas price (default `0.025uqor`); tune both via
9798
+ * multiplier (default 1.4) and gas price (default `0.15uqor`); tune both via
9798
9799
  * `opts.autoFee`.
9799
9800
  *
9800
9801
  * Broadcast mode maps onto cosmjs transports:
@@ -10450,14 +10451,14 @@ function generatePqcKeypair(seed) {
10450
10451
  );
10451
10452
  }
10452
10453
  const xi = seed ?? utils.randomBytes(ML_DSA_87_SEED_LENGTH);
10453
- const kp = mlDsa_js.ml_dsa87.keygen(xi);
10454
+ const kp = pqc$1.mldsa87.keygen(xi);
10454
10455
  return { publicKey: kp.publicKey, secretKey: kp.secretKey };
10455
10456
  }
10456
- function pqcSign(secretKey, message) {
10457
- return mlDsa_js.ml_dsa87.sign(secretKey, message);
10457
+ function pqcSign(secretKey, message, opts) {
10458
+ return pqc$1.mldsa87.sign(secretKey, message, opts);
10458
10459
  }
10459
10460
  function pqcVerify(publicKey, message, signature) {
10460
- return mlDsa_js.ml_dsa87.verify(publicKey, message, signature);
10461
+ return pqc$1.mldsa87.verify(publicKey, message, signature);
10461
10462
  }
10462
10463
  function buildHybridSignatureExtension(args) {
10463
10464
  const { algorithmId, signature, publicKey } = args;
@@ -19155,7 +19156,7 @@ function suggestChainInfo(network) {
19155
19156
  };
19156
19157
  const feeCurrency = {
19157
19158
  ...currency,
19158
- gasPriceStep: { low: 0.01, average: 0.025, high: 0.04 }
19159
+ gasPriceStep: { low: 0.1, average: 0.15, high: 0.25 }
19159
19160
  };
19160
19161
  return {
19161
19162
  chainId,
@@ -19599,9 +19600,253 @@ function createRollupClient(tx, opts = {}) {
19599
19600
  };
19600
19601
  }
19601
19602
 
19603
+ // src/helpers/crossvm.ts
19604
+ var VM_TYPES = ["evm", "cosmwasm", "svm"];
19605
+ var HEX_RE = /^0x[0-9a-fA-F]*$/;
19606
+ function rawToBytes(data) {
19607
+ if (typeof data !== "string") return data;
19608
+ if (!HEX_RE.test(data)) {
19609
+ throw new Error(
19610
+ `crossvm: invalid hex payload (expected 0x-prefixed hex, got "${data.slice(0, 12)}...")`
19611
+ );
19612
+ }
19613
+ const hex = data.slice(2);
19614
+ const bytes = new Uint8Array(hex.length / 2);
19615
+ for (let i = 0; i < bytes.length; i++) {
19616
+ bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
19617
+ }
19618
+ return bytes;
19619
+ }
19620
+ function cosmwasmToBytes(msg2) {
19621
+ return new TextEncoder().encode(JSON.stringify(msg2));
19622
+ }
19623
+ async function encodePayload(input) {
19624
+ if ("payload" in input) {
19625
+ return rawToBytes(input.payload);
19626
+ }
19627
+ if ("cosmwasm" in input) {
19628
+ return cosmwasmToBytes(input.cosmwasm);
19629
+ }
19630
+ if ("svm" in input) {
19631
+ return rawToBytes(input.svm.data);
19632
+ }
19633
+ const { encodeFunctionData } = await import('viem');
19634
+ const data = encodeFunctionData({
19635
+ // viem's Abi typing is structurally compatible; cast at the boundary.
19636
+ abi: input.evm.abi,
19637
+ functionName: input.evm.functionName,
19638
+ args: input.evm.args ?? []
19639
+ });
19640
+ return rawToBytes(data);
19641
+ }
19642
+ function requireGetMessageSource(query, qor) {
19643
+ if (!query && !qor) {
19644
+ throw new Error(
19645
+ "crossvm getMessage requires a query client or a qor client \u2014 pass { query } or { qor } to createCrossVMClient"
19646
+ );
19647
+ }
19648
+ }
19649
+ function extractMessageIds(result) {
19650
+ const events = result.events;
19651
+ const ids = [];
19652
+ if (Array.isArray(events)) {
19653
+ for (const ev of events) {
19654
+ const attrs = ev.attributes;
19655
+ if (!Array.isArray(attrs)) continue;
19656
+ for (const a of attrs) {
19657
+ const key = String(a.key ?? "");
19658
+ if (key === "message_id" || key === "messageId") {
19659
+ ids.push(String(a.value ?? ""));
19660
+ }
19661
+ }
19662
+ }
19663
+ }
19664
+ return ids;
19665
+ }
19666
+ function createCrossVMClient(tx, opts = {}) {
19667
+ const sender = tx.senderAddress;
19668
+ const query = opts.query;
19669
+ const qor = opts.qor;
19670
+ const buildFrom = (o, payload) => crossvm.crossVmCall({
19671
+ sender,
19672
+ sourceVm: o.sourceVm ?? "evm",
19673
+ targetVm: o.targetVm,
19674
+ targetContract: o.targetContract,
19675
+ payload,
19676
+ funds: o.funds ?? []
19677
+ });
19678
+ const buildCallSync = (o, payload) => buildFrom(o, payload);
19679
+ const buildCall = (o) => {
19680
+ if ("evm" in o) {
19681
+ throw new Error(
19682
+ "crossvm buildCall: EVM payloads are ABI-encoded asynchronously (viem). Use `call`/`callAtomic`, or pre-encode and pass `{ payload }`."
19683
+ );
19684
+ }
19685
+ let payload;
19686
+ if ("payload" in o) payload = rawToBytes(o.payload);
19687
+ else if ("cosmwasm" in o) payload = cosmwasmToBytes(o.cosmwasm);
19688
+ else payload = rawToBytes(o.svm.data);
19689
+ return buildCallSync(o, payload);
19690
+ };
19691
+ const call = async (o) => {
19692
+ const payload = await encodePayload(o);
19693
+ const message = buildFrom(o, payload);
19694
+ const result = await tx.signAndBroadcast(
19695
+ [message],
19696
+ o.fee ?? "auto",
19697
+ o.memo ?? "",
19698
+ { autoFee: o.autoFee }
19699
+ );
19700
+ const [messageId = ""] = extractMessageIds(result);
19701
+ return { messageId, result };
19702
+ };
19703
+ const callAtomic = async (calls, w = {}) => {
19704
+ if (calls.length === 0) {
19705
+ throw new Error("crossvm callAtomic: provide at least one call");
19706
+ }
19707
+ const messages = await Promise.all(
19708
+ calls.map(async (o) => buildFrom(o, await encodePayload(o)))
19709
+ );
19710
+ const result = await tx.signAndBroadcast(
19711
+ messages,
19712
+ w.fee ?? "auto",
19713
+ w.memo ?? "",
19714
+ { autoFee: w.autoFee }
19715
+ );
19716
+ return { messageIds: extractMessageIds(result), result };
19717
+ };
19718
+ const getMessage = (id) => {
19719
+ requireGetMessageSource(query, qor);
19720
+ if (query) return query.message({ id });
19721
+ return qor.getCrossVmMessage(id);
19722
+ };
19723
+ return { call, buildCall, callAtomic, getMessage };
19724
+ }
19725
+
19726
+ // src/helpers/pqc.ts
19727
+ var PQC_KEY_STATUS_PRECOMPILE_ADDRESS = "0x0000000000000000000000000000000000000A02";
19728
+ function resolveQor(source) {
19729
+ if ("qor" in source && source.qor) return source.qor;
19730
+ return source;
19731
+ }
19732
+ function asBool(v) {
19733
+ if (typeof v === "boolean") return v;
19734
+ if (typeof v === "number") return v !== 0;
19735
+ if (typeof v === "string") return v === "true" || v === "1";
19736
+ return false;
19737
+ }
19738
+ function asNumber(v) {
19739
+ if (typeof v === "number") return v;
19740
+ if (typeof v === "string" && v.trim() !== "" && !Number.isNaN(Number(v))) {
19741
+ return Number(v);
19742
+ }
19743
+ return void 0;
19744
+ }
19745
+ async function getPqcStatus(source, address) {
19746
+ const qor = resolveQor(source);
19747
+ const raw = await qor.getPqcKeyStatus(address);
19748
+ if (raw == null || typeof raw !== "object") {
19749
+ return { registered: false };
19750
+ }
19751
+ const registered = asBool(
19752
+ raw.registered ?? raw.isRegistered ?? raw.is_registered
19753
+ );
19754
+ const algorithmId = asNumber(raw.algorithmId ?? raw.algorithm_id);
19755
+ const pubkeyRaw = raw.pubkey ?? raw.publicKey ?? raw.public_key;
19756
+ const pubkey = typeof pubkeyRaw === "string" || pubkeyRaw instanceof Uint8Array ? pubkeyRaw : void 0;
19757
+ const status = { registered };
19758
+ if (algorithmId !== void 0) status.algorithmId = algorithmId;
19759
+ if (pubkey !== void 0) status.pubkey = pubkey;
19760
+ return status;
19761
+ }
19762
+ async function isPqcRegistered(source, address) {
19763
+ const status = await getPqcStatus(source, address);
19764
+ return status.registered;
19765
+ }
19766
+ function buildRegisterPqcKeyMsg(sender, opts) {
19767
+ return pqc.registerPqcKeyV2({
19768
+ sender,
19769
+ publicKey: opts.pqcKeypair.publicKey,
19770
+ algorithmId: AlgorithmDilithium5,
19771
+ ecdsaPubkey: opts.ecdsaPubkey ?? new Uint8Array(0),
19772
+ keyType: opts.keyType ?? "hybrid"
19773
+ });
19774
+ }
19775
+ async function ensurePqcRegistered(tx, opts) {
19776
+ const sender = tx.senderAddress;
19777
+ const status = opts.status ?? (opts.statusSource ? await getPqcStatus(opts.statusSource, sender) : void 0);
19778
+ if (status?.registered) {
19779
+ return { alreadyRegistered: true };
19780
+ }
19781
+ const message = buildRegisterPqcKeyMsg(sender, opts);
19782
+ const result = await tx.signAndBroadcast(
19783
+ [message],
19784
+ opts.fee ?? "auto",
19785
+ opts.memo ?? "",
19786
+ { autoFee: opts.autoFee }
19787
+ );
19788
+ return {
19789
+ alreadyRegistered: false,
19790
+ txHash: result.transactionHash,
19791
+ result
19792
+ };
19793
+ }
19794
+ async function migratePqcKey(tx, opts) {
19795
+ const message = pqc.migratePqcKey({
19796
+ sender: tx.senderAddress,
19797
+ oldPublicKey: opts.oldPublicKey,
19798
+ newPublicKey: opts.newPublicKey,
19799
+ newAlgorithmId: opts.newAlgorithmId ?? AlgorithmDilithium5,
19800
+ oldSignature: opts.oldSignature,
19801
+ newSignature: opts.newSignature
19802
+ });
19803
+ return tx.signAndBroadcast([message], opts.fee ?? "auto", opts.memo ?? "", {
19804
+ autoFee: opts.autoFee
19805
+ });
19806
+ }
19807
+ async function migrateToHybrid(tx, opts) {
19808
+ const ensured = await ensurePqcRegistered(tx, opts);
19809
+ const pqcKeypair = opts.pqcKeypair;
19810
+ return {
19811
+ alreadyRegistered: ensured.alreadyRegistered,
19812
+ registrationTxHash: ensured.txHash,
19813
+ pqcKeypair,
19814
+ buildHybridTx: (o) => buildHybridTx({ ...o, pqcKeypair }),
19815
+ signAndBroadcastHybrid: (o) => signAndBroadcastHybrid({ ...o, pqcKeypair })
19816
+ };
19817
+ }
19818
+
19602
19819
  // src/index.ts
19603
- var VERSION = "0.3.0";
19820
+ var VERSION = "0.5.0";
19604
19821
 
19822
+ Object.defineProperty(exports, "AI_ANOMALY_CHECK_ADDRESS", {
19823
+ enumerable: true,
19824
+ get: function () { return evm.AI_ANOMALY_CHECK_ADDRESS; }
19825
+ });
19826
+ Object.defineProperty(exports, "AI_RISK_SCORE_ADDRESS", {
19827
+ enumerable: true,
19828
+ get: function () { return evm.AI_RISK_SCORE_ADDRESS; }
19829
+ });
19830
+ Object.defineProperty(exports, "RISK_LEVEL_UNSAFE_THRESHOLD", {
19831
+ enumerable: true,
19832
+ get: function () { return evm.RISK_LEVEL_UNSAFE_THRESHOLD; }
19833
+ });
19834
+ Object.defineProperty(exports, "ai", {
19835
+ enumerable: true,
19836
+ get: function () { return evm.ai; }
19837
+ });
19838
+ Object.defineProperty(exports, "aiAnomalyCheck", {
19839
+ enumerable: true,
19840
+ get: function () { return evm.aiAnomalyCheck; }
19841
+ });
19842
+ Object.defineProperty(exports, "aiRiskScore", {
19843
+ enumerable: true,
19844
+ get: function () { return evm.aiRiskScore; }
19845
+ });
19846
+ Object.defineProperty(exports, "simulateWithRiskScore", {
19847
+ enumerable: true,
19848
+ get: function () { return evm.simulateWithRiskScore; }
19849
+ });
19605
19850
  exports.AlgorithmDilithium5 = AlgorithmDilithium5;
19606
19851
  exports.AlgorithmMLKEM1024 = AlgorithmMLKEM1024;
19607
19852
  exports.AlgorithmUnspecified = AlgorithmUnspecified;
@@ -19618,6 +19863,7 @@ exports.ML_DSA_87_SEED_LENGTH = ML_DSA_87_SEED_LENGTH;
19618
19863
  exports.ML_DSA_87_SIGNATURE_LENGTH = ML_DSA_87_SIGNATURE_LENGTH;
19619
19864
  exports.MSG_SEND_TYPE_URL = MSG_SEND_TYPE_URL;
19620
19865
  exports.NETWORKS = NETWORKS;
19866
+ exports.PQC_KEY_STATUS_PRECOMPILE_ADDRESS = PQC_KEY_STATUS_PRECOMPILE_ADDRESS;
19621
19867
  exports.PqcSigner = PqcSigner;
19622
19868
  exports.QorClient = QorClient;
19623
19869
  exports.QoreHttpError = QoreHttpError;
@@ -19626,6 +19872,7 @@ exports.RestClient = RestClient;
19626
19872
  exports.STATIC_FALLBACK = STATIC_FALLBACK;
19627
19873
  exports.TxClient = TxClient;
19628
19874
  exports.VERSION = VERSION;
19875
+ exports.VM_TYPES = VM_TYPES;
19629
19876
  exports.abstractaccount = abstractaccount;
19630
19877
  exports.algorithmName = algorithmName;
19631
19878
  exports.amm = amm;
@@ -19639,6 +19886,7 @@ exports.buildAminoTypes = buildAminoTypes;
19639
19886
  exports.buildEventsQuery = buildEventsQuery;
19640
19887
  exports.buildHybridSignatureExtension = buildHybridSignatureExtension;
19641
19888
  exports.buildHybridTx = buildHybridTx;
19889
+ exports.buildRegisterPqcKeyMsg = buildRegisterPqcKeyMsg;
19642
19890
  exports.buildTxQuery = buildTxQuery;
19643
19891
  exports.buildUrl = buildUrl;
19644
19892
  exports.bytesToBech32 = bytesToBech32;
@@ -19648,6 +19896,7 @@ exports.connectCosmWasmSigner = connectCosmWasmSigner;
19648
19896
  exports.connectQueryClients = connectQueryClients;
19649
19897
  exports.createClient = createClient;
19650
19898
  exports.createCosmWasmClient = createCosmWasmClient;
19899
+ exports.createCrossVMClient = createCrossVMClient;
19651
19900
  exports.createMultilayerClient = createMultilayerClient;
19652
19901
  exports.createQueryClients = createQueryClients;
19653
19902
  exports.createRollupClient = createRollupClient;
@@ -19660,6 +19909,7 @@ exports.deriveSvmAccount = deriveSvmAccount;
19660
19909
  exports.directSignerFromPrivateKey = directSignerFromPrivateKey;
19661
19910
  exports.distribution = distribution;
19662
19911
  exports.encodeHybridExtension = encodeHybridExtension;
19912
+ exports.ensurePqcRegistered = ensurePqcRegistered;
19663
19913
  exports.estimateFee = estimateFee;
19664
19914
  exports.evmToQor = evmToQor;
19665
19915
  exports.execute = execute;
@@ -19683,6 +19933,7 @@ exports.getJson = getJson;
19683
19933
  exports.getLatestBlock = getLatestBlock;
19684
19934
  exports.getNetwork = getNetwork;
19685
19935
  exports.getPendingCrossVmMessages = getPendingCrossVmMessages;
19936
+ exports.getPqcStatus = getPqcStatus;
19686
19937
  exports.getTx = getTx;
19687
19938
  exports.gov = gov;
19688
19939
  exports.hexToBech32 = hexToBech32;
@@ -19690,6 +19941,7 @@ exports.ibc = ibc;
19690
19941
  exports.instantiate = instantiate;
19691
19942
  exports.instantiate2 = instantiate2;
19692
19943
  exports.isChecksumAddress = isChecksumAddress;
19944
+ exports.isPqcRegistered = isPqcRegistered;
19693
19945
  exports.isSignatureAlgorithm = isSignatureAlgorithm;
19694
19946
  exports.isTxFailure = isTxFailure;
19695
19947
  exports.isValidBech32 = isValidBech32;
@@ -19702,6 +19954,8 @@ exports.license = license;
19702
19954
  exports.lightnode = lightnode;
19703
19955
  exports.listNetworks = listNetworks;
19704
19956
  exports.migrate = migrate;
19957
+ exports.migratePqcKey = migratePqcKey;
19958
+ exports.migrateToHybrid = migrateToHybrid;
19705
19959
  exports.msg = msg;
19706
19960
  exports.multilayer = multilayer;
19707
19961
  exports.parseUnits = parseUnits;