@qorechain/sdk 0.4.0 → 0.5.0
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/dist/index.cjs +254 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +359 -2
- package/dist/index.d.ts +359 -2
- package/dist/index.js +218 -2
- package/dist/index.js.map +1 -1
- package/package.json +26 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import * as _cosmjs_proto_signing from '@cosmjs/proto-signing';
|
|
2
2
|
import { EncodeObject, OfflineSigner, GeneratedType, Registry, OfflineDirectSigner } from '@cosmjs/proto-signing';
|
|
3
|
+
export { EncodeObject } from '@cosmjs/proto-signing';
|
|
3
4
|
import { Coin as Coin$1, StdFee } from '@cosmjs/amino';
|
|
4
5
|
export { Coin, StdFee } from '@cosmjs/amino';
|
|
5
6
|
import { DeliverTxResponse, AminoTypes, AminoConverters, SigningStargateClientOptions, QueryClient, ProtobufRpcClient } from '@cosmjs/stargate';
|
|
6
7
|
import { CosmWasmClient, SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate';
|
|
8
|
+
export { AI_ANOMALY_CHECK_ADDRESS, AI_RISK_SCORE_ADDRESS, AiAnomalyCheck, AiRiskScore, PreflightResult, PreflightTx, RISK_LEVEL_UNSAFE_THRESHOLD, ai, aiAnomalyCheck, aiRiskScore, simulateWithRiskScore } from '@qorechain/evm';
|
|
7
9
|
import { Any } from 'cosmjs-types/google/protobuf/any';
|
|
8
10
|
import { TxBody, TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
|
|
9
11
|
import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
|
|
@@ -7851,6 +7853,361 @@ interface CreateRollupClientOptions {
|
|
|
7851
7853
|
*/
|
|
7852
7854
|
declare function createRollupClient(tx: TxClient, opts?: CreateRollupClientOptions): RollupClient;
|
|
7853
7855
|
|
|
7856
|
+
/**
|
|
7857
|
+
* High-level Cross-VM client — unified calls across QoreChain's three VMs.
|
|
7858
|
+
*
|
|
7859
|
+
* QoreChain runs EVM, SVM, and CosmWasm side by side and lets a single native
|
|
7860
|
+
* account invoke a contract on any of them through the `x/crossvm` module's
|
|
7861
|
+
* {@link MsgCrossVMCall}. This helper wraps that message — and the cross-VM query
|
|
7862
|
+
* client — so an app developer never hand-builds a `{ typeUrl, value }`, encodes a
|
|
7863
|
+
* payload by hand, or remembers a service/method name.
|
|
7864
|
+
*
|
|
7865
|
+
* The headline capability is {@link CrossVMClient.callAtomic}: pack several
|
|
7866
|
+
* `MsgCrossVMCall` messages into ONE transaction body so they execute atomically
|
|
7867
|
+
* under a single signature — e.g. an EVM call, an SVM call, and a CosmWasm call
|
|
7868
|
+
* that all land together or not at all.
|
|
7869
|
+
*
|
|
7870
|
+
* Per-VM payload encoding (pick exactly one shape per call):
|
|
7871
|
+
* - `{ payload }` — raw bytes / hex, passed through unchanged.
|
|
7872
|
+
* - `{ evm: { abi, functionName, args } }` — ABI-encoded with viem's
|
|
7873
|
+
* `encodeFunctionData` (selector + args). Requires the optional `viem` peer.
|
|
7874
|
+
* - `{ cosmwasm: object }` — `JSON.stringify` then UTF-8 bytes (the CosmWasm
|
|
7875
|
+
* execute-msg convention).
|
|
7876
|
+
* - `{ svm: { data } }` — raw bytes / hex (already an SVM instruction blob).
|
|
7877
|
+
*
|
|
7878
|
+
* Construct one with {@link createCrossVMClient}, passing a connected
|
|
7879
|
+
* {@link TxClient} (for writes) and, optionally, a {@link CrossVmQueryClient}
|
|
7880
|
+
* and/or a {@link QorClient} for the reads.
|
|
7881
|
+
*/
|
|
7882
|
+
|
|
7883
|
+
/** The three execution environments a cross-VM call can target. */
|
|
7884
|
+
type VMType = "evm" | "cosmwasm" | "svm";
|
|
7885
|
+
/** The set of supported VM type strings. */
|
|
7886
|
+
declare const VM_TYPES: readonly ["evm", "cosmwasm", "svm"];
|
|
7887
|
+
/** A hex string (`0x`-prefixed) as accepted for raw payloads. */
|
|
7888
|
+
type Hex = `0x${string}`;
|
|
7889
|
+
/** Raw, pre-encoded payload — passed through to the chain unchanged. */
|
|
7890
|
+
interface RawPayload {
|
|
7891
|
+
/** The opaque payload bytes (raw `Uint8Array` or `0x`-hex). */
|
|
7892
|
+
payload: Uint8Array | Hex;
|
|
7893
|
+
}
|
|
7894
|
+
/** EVM payload built by ABI-encoding a function call with viem. */
|
|
7895
|
+
interface EvmPayload {
|
|
7896
|
+
evm: {
|
|
7897
|
+
/** The contract ABI (viem `Abi`-compatible array). */
|
|
7898
|
+
abi: readonly unknown[];
|
|
7899
|
+
/** The function to call. */
|
|
7900
|
+
functionName: string;
|
|
7901
|
+
/** The call arguments. */
|
|
7902
|
+
args?: readonly unknown[];
|
|
7903
|
+
};
|
|
7904
|
+
}
|
|
7905
|
+
/** CosmWasm payload: a JSON execute-message object (stringified to UTF-8). */
|
|
7906
|
+
interface CosmWasmPayload {
|
|
7907
|
+
/** The CosmWasm execute message (e.g. `{ transfer: { ... } }`). */
|
|
7908
|
+
cosmwasm: object;
|
|
7909
|
+
}
|
|
7910
|
+
/** SVM payload: a pre-built instruction blob (raw bytes / hex). */
|
|
7911
|
+
interface SvmPayload {
|
|
7912
|
+
svm: {
|
|
7913
|
+
/** The SVM instruction data (raw `Uint8Array` or `0x`-hex). */
|
|
7914
|
+
data: Uint8Array | Hex;
|
|
7915
|
+
};
|
|
7916
|
+
}
|
|
7917
|
+
/** Exactly one of the supported payload shapes. */
|
|
7918
|
+
type PayloadInput = RawPayload | EvmPayload | CosmWasmPayload | SvmPayload;
|
|
7919
|
+
/** Shared write-path options forwarded to {@link TxClient.signAndBroadcast}. */
|
|
7920
|
+
interface CrossVMWriteOptions {
|
|
7921
|
+
/** Fee: an explicit `StdFee` or `"auto"` (simulate + price). Default `"auto"`. */
|
|
7922
|
+
fee?: FeeInput$1;
|
|
7923
|
+
/** Optional memo string. */
|
|
7924
|
+
memo?: string;
|
|
7925
|
+
/** Auto-fee tuning (gas multiplier / gas price) when `fee` is `"auto"`. */
|
|
7926
|
+
autoFee?: AutoFeeOptions;
|
|
7927
|
+
}
|
|
7928
|
+
/** Common cross-VM call fields (without the payload or write options). */
|
|
7929
|
+
interface CrossVMCallBase {
|
|
7930
|
+
/** The VM the call originates from. Defaults to `"evm"`. */
|
|
7931
|
+
sourceVm?: VMType;
|
|
7932
|
+
/** The VM the call targets. */
|
|
7933
|
+
targetVm: VMType;
|
|
7934
|
+
/** The target contract address/identifier on `targetVm`. */
|
|
7935
|
+
targetContract: string;
|
|
7936
|
+
/** Optional funds (coins) to forward with the call. */
|
|
7937
|
+
funds?: Coin$1[];
|
|
7938
|
+
}
|
|
7939
|
+
/** Options for a single cross-VM call (base + payload). */
|
|
7940
|
+
type CrossVMCallOptions = CrossVMCallBase & PayloadInput;
|
|
7941
|
+
/** Options for {@link CrossVMClient.call} (adds write-path options). */
|
|
7942
|
+
type CallOptions = CrossVMCallOptions & CrossVMWriteOptions;
|
|
7943
|
+
/** Result of a single {@link CrossVMClient.call}. */
|
|
7944
|
+
interface CrossVMCallResult {
|
|
7945
|
+
/** The cross-VM message id assigned by the chain (parsed from tx events). */
|
|
7946
|
+
messageId: string;
|
|
7947
|
+
/** The raw broadcast result. */
|
|
7948
|
+
result: BroadcastResult;
|
|
7949
|
+
}
|
|
7950
|
+
/** Result of an atomic {@link CrossVMClient.callAtomic} batch. */
|
|
7951
|
+
interface CrossVMAtomicResult {
|
|
7952
|
+
/** The cross-VM message ids assigned by the chain (best-effort, from events). */
|
|
7953
|
+
messageIds: string[];
|
|
7954
|
+
/** The raw broadcast result for the single packing transaction. */
|
|
7955
|
+
result: BroadcastResult;
|
|
7956
|
+
}
|
|
7957
|
+
/**
|
|
7958
|
+
* Ergonomic client for the `x/crossvm` module.
|
|
7959
|
+
*
|
|
7960
|
+
* Writes build + sign + broadcast a {@link MsgCrossVMCall}; {@link callAtomic}
|
|
7961
|
+
* packs several into one body. {@link buildCall} is the offline build-only path.
|
|
7962
|
+
* Reads return the typed query response (or the `qor_` JSON-RPC fallback).
|
|
7963
|
+
*/
|
|
7964
|
+
interface CrossVMClient {
|
|
7965
|
+
/** Build, sign, and broadcast a single cross-VM call. */
|
|
7966
|
+
call(opts: CallOptions): Promise<CrossVMCallResult>;
|
|
7967
|
+
/** Build a single `MsgCrossVMCall` without broadcasting. */
|
|
7968
|
+
buildCall(opts: CrossVMCallOptions): EncodeObject;
|
|
7969
|
+
/**
|
|
7970
|
+
* Pack multiple cross-VM calls into ONE transaction body so they execute
|
|
7971
|
+
* atomically under a single signature (the triple-VM headline).
|
|
7972
|
+
*/
|
|
7973
|
+
callAtomic(calls: CrossVMCallOptions[], opts?: CrossVMWriteOptions): Promise<CrossVMAtomicResult>;
|
|
7974
|
+
/**
|
|
7975
|
+
* Read a cross-VM message by id. Uses the typed query client when provided,
|
|
7976
|
+
* otherwise falls back to the `qor_getCrossVMMessage` JSON-RPC method.
|
|
7977
|
+
*/
|
|
7978
|
+
getMessage(id: string): Promise<QueryMessageResponse | Record<string, unknown>>;
|
|
7979
|
+
}
|
|
7980
|
+
/** Options for {@link createCrossVMClient}. */
|
|
7981
|
+
interface CreateCrossVMClientOptions {
|
|
7982
|
+
/**
|
|
7983
|
+
* Typed query client for {@link CrossVMClient.getMessage} (preferred). Obtain
|
|
7984
|
+
* it via {@link connectQueryClients} / {@link createQueryClients}.
|
|
7985
|
+
*/
|
|
7986
|
+
query?: CrossVmQueryClient;
|
|
7987
|
+
/**
|
|
7988
|
+
* `qor_` JSON-RPC client used as the {@link CrossVMClient.getMessage} fallback
|
|
7989
|
+
* (via `qor_getCrossVMMessage`) when no typed query client is supplied.
|
|
7990
|
+
*/
|
|
7991
|
+
qor?: QorClient;
|
|
7992
|
+
}
|
|
7993
|
+
/**
|
|
7994
|
+
* Create a {@link CrossVMClient} bound to a connected {@link TxClient}.
|
|
7995
|
+
*
|
|
7996
|
+
* The `TxClient`'s sender address is used as the message `sender`, so the caller
|
|
7997
|
+
* never repeats their address. `sourceVm` defaults to `"evm"`.
|
|
7998
|
+
*
|
|
7999
|
+
* @param tx - A connected signing client (from `client.connectTx(signer)`).
|
|
8000
|
+
* @param opts - Optional typed query client and/or `qor_` client for reads.
|
|
8001
|
+
*/
|
|
8002
|
+
declare function createCrossVMClient(tx: TxClient, opts?: CreateCrossVMClientOptions): CrossVMClient;
|
|
8003
|
+
|
|
8004
|
+
/**
|
|
8005
|
+
* High-level quantum-safe developer-experience helpers.
|
|
8006
|
+
*
|
|
8007
|
+
* QoreChain treats post-quantum cryptography (PQC) as a first-class signature
|
|
8008
|
+
* scheme: an account registers an ML-DSA-87 (Dilithium-5) key on-chain
|
|
8009
|
+
* (`MsgRegisterPQCKey`), after which its transactions can carry a hybrid
|
|
8010
|
+
* (classical secp256k1 + ML-DSA-87) signature that the ante handler verifies in
|
|
8011
|
+
* full. The low-level primitives already exist — {@link generatePqcKeypair},
|
|
8012
|
+
* {@link buildHybridTx}, {@link signAndBroadcastHybrid}, the
|
|
8013
|
+
* `msg.pqc.registerPqcKey` composer, and the `qor_getPQCKeyStatus` read. This
|
|
8014
|
+
* module wraps them into a tiny, idempotent surface so a dApp becomes
|
|
8015
|
+
* **quantum-safe by default**: one call to be PQC-protected.
|
|
8016
|
+
*
|
|
8017
|
+
* The headline calls:
|
|
8018
|
+
* - {@link isPqcRegistered} / {@link getPqcStatus} — read whether an address has
|
|
8019
|
+
* a registered PQC key (via `qor_getPQCKeyStatus`).
|
|
8020
|
+
* - {@link ensurePqcRegistered} — register the signer's Dilithium key if (and
|
|
8021
|
+
* only if) it is not already registered. Idempotent: safe to call on every
|
|
8022
|
+
* app start.
|
|
8023
|
+
* - {@link migrateToHybrid} — ensure registration, then hand back a hybrid send
|
|
8024
|
+
* path wired to {@link buildHybridTx} / {@link signAndBroadcastHybrid}.
|
|
8025
|
+
* - {@link migratePqcKey} — rotate an account's PQC key (`MsgMigratePQCKey`).
|
|
8026
|
+
*
|
|
8027
|
+
* Reads accept either a {@link QorClient} or anything exposing a `qor`
|
|
8028
|
+
* sub-client (e.g. the composed `QoreChainClient` from `createClient`). Writes
|
|
8029
|
+
* take a connected {@link TxClient}.
|
|
8030
|
+
*
|
|
8031
|
+
* Precompile alternative: the same status is readable on the EVM side via the
|
|
8032
|
+
* `pqcKeyStatus(address) returns (bool registered, uint8 algorithmId, bytes
|
|
8033
|
+
* pubkey)` precompile at `0x0000000000000000000000000000000000000A02` (exposed
|
|
8034
|
+
* as `pqcKeyStatus` in `@qorechain/evm`). The helpers below prefer the
|
|
8035
|
+
* `qor_getPQCKeyStatus` JSON-RPC method, which needs no viem peer; the
|
|
8036
|
+
* precompile is the documented alternative for callers already on the EVM side.
|
|
8037
|
+
*/
|
|
8038
|
+
|
|
8039
|
+
/** EVM precompile address for the `pqcKeyStatus` read (documented alternative). */
|
|
8040
|
+
declare const PQC_KEY_STATUS_PRECOMPILE_ADDRESS = "0x0000000000000000000000000000000000000A02";
|
|
8041
|
+
/**
|
|
8042
|
+
* A source for PQC status reads: either a {@link QorClient} directly, or any
|
|
8043
|
+
* object exposing one as `.qor` (e.g. the composed `QoreChainClient`).
|
|
8044
|
+
*/
|
|
8045
|
+
type PqcStatusSource = QorClient | {
|
|
8046
|
+
qor: QorClient;
|
|
8047
|
+
};
|
|
8048
|
+
/** Normalized PQC registration status for an address. */
|
|
8049
|
+
interface PqcStatus {
|
|
8050
|
+
/** Whether the address has a registered PQC key. */
|
|
8051
|
+
registered: boolean;
|
|
8052
|
+
/** The registered algorithm id, when known (Dilithium-5 = {@link AlgorithmDilithium5}). */
|
|
8053
|
+
algorithmId?: number;
|
|
8054
|
+
/** The registered PQC public key, when the chain returns it (hex or bytes). */
|
|
8055
|
+
pubkey?: string | Uint8Array;
|
|
8056
|
+
}
|
|
8057
|
+
/**
|
|
8058
|
+
* Read the PQC registration status of an address via `qor_getPQCKeyStatus`.
|
|
8059
|
+
*
|
|
8060
|
+
* The chain returns a rich JSON object; this helper normalizes the common
|
|
8061
|
+
* fields (`registered`, `algorithmId`/`algorithm_id`, `pubkey`/`public_key`)
|
|
8062
|
+
* into a {@link PqcStatus}. Unknown shapes degrade to `{ registered: false }`.
|
|
8063
|
+
*
|
|
8064
|
+
* Alternative: on the EVM side, call the `pqcKeyStatus(address)` precompile at
|
|
8065
|
+
* {@link PQC_KEY_STATUS_PRECOMPILE_ADDRESS} (via `@qorechain/evm`).
|
|
8066
|
+
*/
|
|
8067
|
+
declare function getPqcStatus(source: PqcStatusSource, address: string): Promise<PqcStatus>;
|
|
8068
|
+
/**
|
|
8069
|
+
* Whether `address` has a registered PQC key.
|
|
8070
|
+
*
|
|
8071
|
+
* Thin boolean wrapper over {@link getPqcStatus} using `qor_getPQCKeyStatus`
|
|
8072
|
+
* (preferred). The EVM `pqcKeyStatus` precompile is the documented alternative.
|
|
8073
|
+
*/
|
|
8074
|
+
declare function isPqcRegistered(source: PqcStatusSource, address: string): Promise<boolean>;
|
|
8075
|
+
/** Options for {@link ensurePqcRegistered}. */
|
|
8076
|
+
interface EnsurePqcRegisteredOptions {
|
|
8077
|
+
/**
|
|
8078
|
+
* The signer's ML-DSA-87 (Dilithium-5) keypair. Its `publicKey` is registered
|
|
8079
|
+
* on-chain as the account's Dilithium key.
|
|
8080
|
+
*/
|
|
8081
|
+
pqcKeypair: PqcKeypair;
|
|
8082
|
+
/**
|
|
8083
|
+
* The account's classical ECDSA (secp256k1) public key, registered alongside
|
|
8084
|
+
* the Dilithium key. When omitted, an empty key is sent — the chain binds the
|
|
8085
|
+
* registration to the transaction signer, so this is optional for accounts
|
|
8086
|
+
* whose classical key is already known on-chain.
|
|
8087
|
+
*/
|
|
8088
|
+
ecdsaPubkey?: Uint8Array;
|
|
8089
|
+
/** Key-type tag forwarded to `MsgRegisterPQCKey` (default `"hybrid"`). */
|
|
8090
|
+
keyType?: string;
|
|
8091
|
+
/** Fee: explicit `StdFee` or `"auto"` (simulate + price). Default `"auto"`. */
|
|
8092
|
+
fee?: FeeInput$1;
|
|
8093
|
+
/** Optional memo string. */
|
|
8094
|
+
memo?: string;
|
|
8095
|
+
/** Auto-fee tuning when `fee` is `"auto"`. */
|
|
8096
|
+
autoFee?: AutoFeeOptions;
|
|
8097
|
+
/**
|
|
8098
|
+
* A pre-read status to avoid a redundant `qor_getPQCKeyStatus` round-trip. When
|
|
8099
|
+
* provided and `registered`, the registration is skipped.
|
|
8100
|
+
*/
|
|
8101
|
+
status?: PqcStatus;
|
|
8102
|
+
/**
|
|
8103
|
+
* A status source for the pre-flight registration check. When omitted, the
|
|
8104
|
+
* registration message is broadcast unconditionally (relying on the chain's
|
|
8105
|
+
* own idempotency) — pass `{ qor }` to make the helper truly idempotent.
|
|
8106
|
+
*/
|
|
8107
|
+
statusSource?: PqcStatusSource;
|
|
8108
|
+
}
|
|
8109
|
+
/** Result of {@link ensurePqcRegistered}. */
|
|
8110
|
+
interface EnsurePqcRegisteredResult {
|
|
8111
|
+
/** `true` when the key was already registered (no transaction was sent). */
|
|
8112
|
+
alreadyRegistered: boolean;
|
|
8113
|
+
/** The registration transaction hash, when a registration was broadcast. */
|
|
8114
|
+
txHash?: string;
|
|
8115
|
+
/** The raw broadcast result, when a registration was broadcast. */
|
|
8116
|
+
result?: BroadcastResult;
|
|
8117
|
+
}
|
|
8118
|
+
/**
|
|
8119
|
+
* Build the `MsgRegisterPQCKey` for a signer without broadcasting.
|
|
8120
|
+
*
|
|
8121
|
+
* Useful for packing registration into a larger transaction body, or for the
|
|
8122
|
+
* offline build path.
|
|
8123
|
+
*/
|
|
8124
|
+
declare function buildRegisterPqcKeyMsg(sender: string, opts: Pick<EnsurePqcRegisteredOptions, "pqcKeypair" | "ecdsaPubkey" | "keyType">): EncodeObject;
|
|
8125
|
+
/**
|
|
8126
|
+
* Register the signer's PQC key if it is not already registered — idempotent.
|
|
8127
|
+
*
|
|
8128
|
+
* If a {@link EnsurePqcRegisteredOptions.statusSource} (or pre-read `status`) is
|
|
8129
|
+
* supplied and the key is already registered, this returns
|
|
8130
|
+
* `{ alreadyRegistered: true }` WITHOUT broadcasting. Otherwise it builds and
|
|
8131
|
+
* broadcasts `MsgRegisterPQCKey` with the signer's Dilithium public key (from
|
|
8132
|
+
* `pqcKeypair`) plus the supplied ECDSA public key.
|
|
8133
|
+
*
|
|
8134
|
+
* This is the single call that makes a dApp quantum-safe: run it once at startup
|
|
8135
|
+
* (or before the first hybrid tx) and the account is PQC-protected thereafter.
|
|
8136
|
+
*
|
|
8137
|
+
* @param tx - A connected signing client (the sender address is its identity).
|
|
8138
|
+
* @param opts - The signer's PQC keypair, optional ECDSA pubkey, and write opts.
|
|
8139
|
+
*/
|
|
8140
|
+
declare function ensurePqcRegistered(tx: TxClient, opts: EnsurePqcRegisteredOptions): Promise<EnsurePqcRegisteredResult>;
|
|
8141
|
+
/** Options for {@link migratePqcKey} (PQC key rotation). */
|
|
8142
|
+
interface MigratePqcKeyOptions {
|
|
8143
|
+
/** The current (old) PQC public key being rotated out. */
|
|
8144
|
+
oldPublicKey: Uint8Array;
|
|
8145
|
+
/** The new PQC public key to register. */
|
|
8146
|
+
newPublicKey: Uint8Array;
|
|
8147
|
+
/** The new key's algorithm id (default {@link AlgorithmDilithium5}). */
|
|
8148
|
+
newAlgorithmId?: number;
|
|
8149
|
+
/** Signature by the OLD key proving ownership of the rotation request. */
|
|
8150
|
+
oldSignature: Uint8Array;
|
|
8151
|
+
/** Signature by the NEW key proving ownership of the new key. */
|
|
8152
|
+
newSignature: Uint8Array;
|
|
8153
|
+
/** Fee: explicit `StdFee` or `"auto"`. Default `"auto"`. */
|
|
8154
|
+
fee?: FeeInput$1;
|
|
8155
|
+
/** Optional memo string. */
|
|
8156
|
+
memo?: string;
|
|
8157
|
+
/** Auto-fee tuning when `fee` is `"auto"`. */
|
|
8158
|
+
autoFee?: AutoFeeOptions;
|
|
8159
|
+
}
|
|
8160
|
+
/**
|
|
8161
|
+
* Rotate an account's PQC key via `MsgMigratePQCKey`.
|
|
8162
|
+
*
|
|
8163
|
+
* The chain proves ownership of BOTH the old and new keys (the caller supplies
|
|
8164
|
+
* `oldSignature` / `newSignature` per the chain's migration contract), so key
|
|
8165
|
+
* rotation never strands an account. Use this when upgrading algorithms or
|
|
8166
|
+
* rolling a compromised key.
|
|
8167
|
+
*/
|
|
8168
|
+
declare function migratePqcKey(tx: TxClient, opts: MigratePqcKeyOptions): Promise<BroadcastResult>;
|
|
8169
|
+
/** Options for {@link migrateToHybrid}. */
|
|
8170
|
+
interface MigrateToHybridOptions extends EnsurePqcRegisteredOptions {
|
|
8171
|
+
/**
|
|
8172
|
+
* A status source used both for the registration pre-flight and (when omitted
|
|
8173
|
+
* elsewhere) the idempotency check. Forwarded to {@link ensurePqcRegistered}.
|
|
8174
|
+
*/
|
|
8175
|
+
statusSource?: PqcStatusSource;
|
|
8176
|
+
}
|
|
8177
|
+
/**
|
|
8178
|
+
* A hybrid send path returned by {@link migrateToHybrid}: the PQC key is
|
|
8179
|
+
* guaranteed registered, and these methods build / broadcast hybrid (classical +
|
|
8180
|
+
* ML-DSA-87) transactions via {@link buildHybridTx} / {@link signAndBroadcastHybrid}.
|
|
8181
|
+
*
|
|
8182
|
+
* The `pqcKeypair` is bound, so callers pass everything else hybrid signing
|
|
8183
|
+
* needs (registry, classical signer, chainId, account number, sequence, ...).
|
|
8184
|
+
*/
|
|
8185
|
+
interface HybridSendPath {
|
|
8186
|
+
/** Whether the PQC key was already registered before this call. */
|
|
8187
|
+
alreadyRegistered: boolean;
|
|
8188
|
+
/** The registration tx hash, when a registration was broadcast. */
|
|
8189
|
+
registrationTxHash?: string;
|
|
8190
|
+
/** The bound ML-DSA-87 keypair used for the hybrid half. */
|
|
8191
|
+
pqcKeypair: PqcKeypair;
|
|
8192
|
+
/** Build a fully signed hybrid tx (PQC keypair pre-bound). */
|
|
8193
|
+
buildHybridTx(opts: Omit<BuildHybridTxOptions, "pqcKeypair">): Promise<BuiltHybridTx>;
|
|
8194
|
+
/** Build, sign, and broadcast a hybrid tx (PQC keypair pre-bound). */
|
|
8195
|
+
signAndBroadcastHybrid(opts: Omit<SignAndBroadcastHybridOptions, "pqcKeypair">): Promise<BroadcastResult>;
|
|
8196
|
+
}
|
|
8197
|
+
/**
|
|
8198
|
+
* Make an account quantum-safe and hand back a hybrid send path.
|
|
8199
|
+
*
|
|
8200
|
+
* Ensures the signer's PQC key is registered (idempotent — see
|
|
8201
|
+
* {@link ensurePqcRegistered}), then returns a {@link HybridSendPath} with the
|
|
8202
|
+
* keypair pre-bound to the existing {@link buildHybridTx} /
|
|
8203
|
+
* {@link signAndBroadcastHybrid} builders. After this call, the dApp's
|
|
8204
|
+
* transactions can carry a verified hybrid signature.
|
|
8205
|
+
*
|
|
8206
|
+
* @param tx - A connected signing client (used for the registration tx).
|
|
8207
|
+
* @param opts - The PQC keypair and registration/idempotency options.
|
|
8208
|
+
*/
|
|
8209
|
+
declare function migrateToHybrid(tx: TxClient, opts: MigrateToHybridOptions): Promise<HybridSendPath>;
|
|
8210
|
+
|
|
7854
8211
|
/**
|
|
7855
8212
|
* `@qorechain/sdk` public API.
|
|
7856
8213
|
*
|
|
@@ -7860,6 +8217,6 @@ declare function createRollupClient(tx: TxClient, opts?: CreateRollupClientOptio
|
|
|
7860
8217
|
* callers who want to compose them directly. Internal helpers are not exported.
|
|
7861
8218
|
*/
|
|
7862
8219
|
/** SDK version. */
|
|
7863
|
-
declare const VERSION = "0.
|
|
8220
|
+
declare const VERSION = "0.5.0";
|
|
7864
8221
|
|
|
7865
|
-
export { type Account, AlgorithmDilithium5, type AlgorithmID, AlgorithmMLKEM1024, AlgorithmUnspecified, type AllBalancesResponse, type AnchorStateOptions, type AttachHybridOptions, type AutoFeeOptions, type BalanceResponse, type BankSendOptions, type Bech32Config, type Bech32Prefixes, type BridgeQueryClient, type BroadcastMode, type BroadcastResult, type BuildHybridTxOptions, type BuiltHybridTx, type ChallengeBatchOptions, type ClientFees, type CoinInfo, type ConnectTxOptions, type ContractMsg, type CosmWasmReadClient, type CosmWasmSigningClient, type CosmosWalletConnection, type CosmosWalletName, type CreateClientOptions, type CreateMultilayerClientOptions, type CreateRollupClientOptions, type CreateRollupOptions, type CrossVmMessage, type CrossVmMessageResponse, type CrossVmParamsResponse, type CrossVmQueryClient, DEFAULT_GAS_MULTIPLIER, DEFAULT_GAS_PRICE, type DecodedTxError, type DenomOptions, type DerivationOptions, type Ed25519Account, type EstimateFeeOptions, type EventFilters, type EventStream, type ExecuteWithdrawalOptions, type ExplorerConfig, type FaucetConfig, type FeeInput, type FeeUrgency, type FetchLike, GasPrice, type GetBlockResponse, type GetCosmosWalletOptions, type GetJsonOptions, type GetTxFn, type GetTxResponse, HYBRID_SIG_TYPE_URL, type Handler, type HashInput, type HttpOptions, type HybridBroadcaster, type HybridPlacement, HybridSigner, type IncludedTx, type InjectedCosmosWallet, type InstantiateOpts, JsonRpcClient, type JsonRpcClientOptions, JsonRpcError, type JsonRpcErrorObject, type JsonRpcResponse, type KeplrChainInfo, type KeplrCurrency, type KeplrFeeCurrency, type KeyType, type LightNodeQueryClient, 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, type MultilayerClient, type MultilayerQueryClient, type MultilayerWriteOptions, NETWORKS, type NetworkConfig, type NetworkEndpoints, type NetworkName, type NewBlockEventLike, type PQCHybridSignature, type PageResponse, type PaginatedOptions, type Pagination, type PendingCrossVmMessagesResponse, type PqcKeypair, type PqcQueryClient, type PqcSignaturePart, PqcSigner, type QcaQueryClient, QorClient, type QoreChainClient, type QoreChainQueryClients, QoreHttpError, QoreTxError, type QueryValue, type RdkQueryClient, type RegisterPaychainOptions, type RegisterSidechainOptions, type ReputationQueryClient, type RequestFaucetOptions, type ResolveChallengeOptions, RestClient, type RestClientOptions, type RetryOptions, type RlConsensusQueryClient, type RollupClient, type RollupLifecycleOptions, type RollupWriteOptions, type RouteTransactionOptions, STATIC_FALLBACK, type SearchTxsOptions, type SearchTxsResponse, type Secp256k1Account, type SignAndBroadcastHybridOptions, type SignAndBroadcastOptions, type SignOutput, type SignatureMode, type Signer, type SigningClientLike, type SimulateOptions, type SubmitBatchOptions, type SubscriptionClient, type SvmQueryClient, type SyncBroadcaster, TxClient, type TxClientOptions, type TxConnectOptions, type TxErrorInput, type TxEventLike, type FeeInput$1 as TxFeeInput, type TxOrderBy, type TxQueryFilters, type TxResultLike, type Unsubscribe, VERSION, type WaitForTxOptions, 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, index 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, withRetry };
|
|
8222
|
+
export { type Account, AlgorithmDilithium5, type AlgorithmID, AlgorithmMLKEM1024, AlgorithmUnspecified, type AllBalancesResponse, type AnchorStateOptions, type AttachHybridOptions, type AutoFeeOptions, type BalanceResponse, type BankSendOptions, type Bech32Config, type Bech32Prefixes, type BridgeQueryClient, type BroadcastMode, type BroadcastResult, type BuildHybridTxOptions, type BuiltHybridTx, type CallOptions, type ChallengeBatchOptions, type ClientFees, type CoinInfo, type ConnectTxOptions, type ContractMsg, type CosmWasmPayload, type CosmWasmReadClient, type CosmWasmSigningClient, type CosmosWalletConnection, type CosmosWalletName, type CreateClientOptions, type CreateCrossVMClientOptions, type CreateMultilayerClientOptions, type CreateRollupClientOptions, type CreateRollupOptions, type CrossVMAtomicResult, type CrossVMCallBase, type CrossVMCallOptions, type CrossVMCallResult, type CrossVMClient, type CrossVMWriteOptions, type CrossVmMessage, type CrossVmMessageResponse, type CrossVmParamsResponse, type CrossVmQueryClient, DEFAULT_GAS_MULTIPLIER, DEFAULT_GAS_PRICE, type DecodedTxError, type DenomOptions, type DerivationOptions, type Ed25519Account, type EnsurePqcRegisteredOptions, type EnsurePqcRegisteredResult, type EstimateFeeOptions, type EventFilters, type EventStream, type EvmPayload, type ExecuteWithdrawalOptions, type ExplorerConfig, type FaucetConfig, type FeeInput, type FeeUrgency, type FetchLike, GasPrice, type GetBlockResponse, type GetCosmosWalletOptions, type GetJsonOptions, type GetTxFn, type GetTxResponse, HYBRID_SIG_TYPE_URL, type Handler, type HashInput, type HttpOptions, type HybridBroadcaster, type HybridPlacement, type HybridSendPath, HybridSigner, type IncludedTx, type InjectedCosmosWallet, type InstantiateOpts, JsonRpcClient, type JsonRpcClientOptions, JsonRpcError, type JsonRpcErrorObject, type JsonRpcResponse, type KeplrChainInfo, type KeplrCurrency, type KeplrFeeCurrency, type KeyType, type LightNodeQueryClient, 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, type MigratePqcKeyOptions, type MigrateToHybridOptions, type MultilayerClient, type MultilayerQueryClient, type MultilayerWriteOptions, NETWORKS, type NetworkConfig, type NetworkEndpoints, type NetworkName, type NewBlockEventLike, type PQCHybridSignature, PQC_KEY_STATUS_PRECOMPILE_ADDRESS, type PageResponse, type PaginatedOptions, type Pagination, type PayloadInput, type PendingCrossVmMessagesResponse, type PqcKeypair, type PqcQueryClient, type PqcSignaturePart, PqcSigner, type PqcStatus, type PqcStatusSource, type QcaQueryClient, QorClient, type QoreChainClient, type QoreChainQueryClients, QoreHttpError, QoreTxError, type QueryValue, type RawPayload, type RdkQueryClient, type RegisterPaychainOptions, type RegisterSidechainOptions, type ReputationQueryClient, type RequestFaucetOptions, type ResolveChallengeOptions, RestClient, type RestClientOptions, type RetryOptions, type RlConsensusQueryClient, type RollupClient, type RollupLifecycleOptions, type RollupWriteOptions, type RouteTransactionOptions, STATIC_FALLBACK, type SearchTxsOptions, type SearchTxsResponse, type Secp256k1Account, type SignAndBroadcastHybridOptions, type SignAndBroadcastOptions, type SignOutput, type SignatureMode, type Signer, type SigningClientLike, type SimulateOptions, type SubmitBatchOptions, type SubscriptionClient, type SvmPayload, type SvmQueryClient, type SyncBroadcaster, TxClient, type TxClientOptions, type TxConnectOptions, type TxErrorInput, type TxEventLike, type FeeInput$1 as TxFeeInput, type TxOrderBy, type TxQueryFilters, type TxResultLike, type Unsubscribe, VERSION, type VMType, VM_TYPES, type WaitForTxOptions, 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, index 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, withRetry };
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,7 @@ import { HDKey } from 'micro-key-producer/slip10.js';
|
|
|
16
16
|
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
17
17
|
import { ml_dsa87 } from '@noble/post-quantum/ml-dsa.js';
|
|
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';
|
|
@@ -19597,9 +19598,224 @@ 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.registerPqcKey({
|
|
19766
|
+
sender,
|
|
19767
|
+
dilithiumPubkey: opts.pqcKeypair.publicKey,
|
|
19768
|
+
ecdsaPubkey: opts.ecdsaPubkey ?? new Uint8Array(0),
|
|
19769
|
+
keyType: opts.keyType ?? "hybrid"
|
|
19770
|
+
});
|
|
19771
|
+
}
|
|
19772
|
+
async function ensurePqcRegistered(tx, opts) {
|
|
19773
|
+
const sender = tx.senderAddress;
|
|
19774
|
+
const status = opts.status ?? (opts.statusSource ? await getPqcStatus(opts.statusSource, sender) : void 0);
|
|
19775
|
+
if (status?.registered) {
|
|
19776
|
+
return { alreadyRegistered: true };
|
|
19777
|
+
}
|
|
19778
|
+
const message = buildRegisterPqcKeyMsg(sender, opts);
|
|
19779
|
+
const result = await tx.signAndBroadcast(
|
|
19780
|
+
[message],
|
|
19781
|
+
opts.fee ?? "auto",
|
|
19782
|
+
opts.memo ?? "",
|
|
19783
|
+
{ autoFee: opts.autoFee }
|
|
19784
|
+
);
|
|
19785
|
+
return {
|
|
19786
|
+
alreadyRegistered: false,
|
|
19787
|
+
txHash: result.transactionHash,
|
|
19788
|
+
result
|
|
19789
|
+
};
|
|
19790
|
+
}
|
|
19791
|
+
async function migratePqcKey(tx, opts) {
|
|
19792
|
+
const message = pqc.migratePqcKey({
|
|
19793
|
+
sender: tx.senderAddress,
|
|
19794
|
+
oldPublicKey: opts.oldPublicKey,
|
|
19795
|
+
newPublicKey: opts.newPublicKey,
|
|
19796
|
+
newAlgorithmId: opts.newAlgorithmId ?? AlgorithmDilithium5,
|
|
19797
|
+
oldSignature: opts.oldSignature,
|
|
19798
|
+
newSignature: opts.newSignature
|
|
19799
|
+
});
|
|
19800
|
+
return tx.signAndBroadcast([message], opts.fee ?? "auto", opts.memo ?? "", {
|
|
19801
|
+
autoFee: opts.autoFee
|
|
19802
|
+
});
|
|
19803
|
+
}
|
|
19804
|
+
async function migrateToHybrid(tx, opts) {
|
|
19805
|
+
const ensured = await ensurePqcRegistered(tx, opts);
|
|
19806
|
+
const pqcKeypair = opts.pqcKeypair;
|
|
19807
|
+
return {
|
|
19808
|
+
alreadyRegistered: ensured.alreadyRegistered,
|
|
19809
|
+
registrationTxHash: ensured.txHash,
|
|
19810
|
+
pqcKeypair,
|
|
19811
|
+
buildHybridTx: (o) => buildHybridTx({ ...o, pqcKeypair }),
|
|
19812
|
+
signAndBroadcastHybrid: (o) => signAndBroadcastHybrid({ ...o, pqcKeypair })
|
|
19813
|
+
};
|
|
19814
|
+
}
|
|
19815
|
+
|
|
19600
19816
|
// src/index.ts
|
|
19601
|
-
var VERSION = "0.
|
|
19817
|
+
var VERSION = "0.5.0";
|
|
19602
19818
|
|
|
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 };
|
|
19819
|
+
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
19820
|
//# sourceMappingURL=index.js.map
|
|
19605
19821
|
//# sourceMappingURL=index.js.map
|