@molpha/sdk 0.2.0 → 0.3.0-dev-20261022065307
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/README.md +72 -59
- package/dist/{chunk-H77BBZOL.js → chunk-KLHORIAC.js} +18 -7
- package/dist/chunk-KLHORIAC.js.map +1 -0
- package/dist/index.d.ts +453 -74
- package/dist/index.js +3781 -469
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/dist/{wallet-DGe_pi93.d.ts → wallet-BAxBy7hR.d.ts} +11 -45
- package/idl/molpha.json +2 -2
- package/package.json +47 -29
- package/dist/chunk-H77BBZOL.js.map +0 -1
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Wallet } from '@anchor-lang/core';
|
|
2
|
-
import {
|
|
2
|
+
import { o as SolanaKeypair, M as MolphaWallet } from './wallet-BAxBy7hR.js';
|
|
3
3
|
import '@solana/kit';
|
|
4
4
|
|
|
5
5
|
/** Load a Solana CLI keypair JSON file (array of 64 bytes) into a `Keypair`. */
|
package/dist/utils.js
CHANGED
|
@@ -37,48 +37,7 @@ interface NodeKeyVerifierArgs {
|
|
|
37
37
|
* private API request before secrets are encrypted or posted.
|
|
38
38
|
*/
|
|
39
39
|
type NodeKeyVerifier = (args: NodeKeyVerifierArgs) => void | Promise<void>;
|
|
40
|
-
/**
|
|
41
|
-
interface APIConfig {
|
|
42
|
-
url: string;
|
|
43
|
-
method?: "GET" | "POST" | "PUT";
|
|
44
|
-
headers?: Record<string, string>;
|
|
45
|
-
/** Expression that extracts the value from the HTTP response. */
|
|
46
|
-
responseParser: string;
|
|
47
|
-
/** Optional expression applied to the parsed value before packing. */
|
|
48
|
-
valueTransform?: string;
|
|
49
|
-
/**
|
|
50
|
-
* Median tolerance mode. Part of the `sourceId`; OMIT it for exact mode. See
|
|
51
|
-
* {@link AggregationConfig}.
|
|
52
|
-
*/
|
|
53
|
-
aggregation?: AggregationConfig;
|
|
54
|
-
}
|
|
55
|
-
/** Numeric encoding of a tolerance-mode value: a signed `int256` scaled by `10^decimals`. */
|
|
56
|
-
interface NumericConfig {
|
|
57
|
-
type: "int256";
|
|
58
|
-
/** Fractional digits, `0..255` (u8). The parsed decimal is scaled by `10^decimals`, rounded half to even. */
|
|
59
|
-
decimals: number;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Median tolerance aggregation. Instead of requiring every signer to fetch the identical
|
|
63
|
-
* value, the selected nodes exchange signed observations, drop stale ones (`maxAgeMs`) and
|
|
64
|
-
* those further than `maxDeviationBps` from the lower median, and sign the lower median of
|
|
65
|
-
* `signaturesRequired` surviving observations. The signed value is a signed `int256`
|
|
66
|
-
* (`encodeInt256Decimal`, `decodeInt256`, `formatInt256Decimal`).
|
|
67
|
-
*
|
|
68
|
-
* The whole object is hashed into the `sourceId` in exactly this key order. Requires
|
|
69
|
-
* `signaturesRequired >= 3`. `mode: "exact"` is rejected: exact mode is expressed by
|
|
70
|
-
* omitting `aggregation`.
|
|
71
|
-
*/
|
|
72
|
-
interface AggregationConfig {
|
|
73
|
-
mode: "tolerance";
|
|
74
|
-
rule: "median";
|
|
75
|
-
/** u32. Allowed deviation from the lower median, in basis points. */
|
|
76
|
-
maxDeviationBps: number;
|
|
77
|
-
/** Positive integer (u64 on the node, ≤ 2^53-1 here). Max observation age, in milliseconds. */
|
|
78
|
-
maxAgeMs: number;
|
|
79
|
-
numeric: NumericConfig;
|
|
80
|
-
}
|
|
81
|
-
/** ECDH-wrapped API config payload sent to selected nodes. */
|
|
40
|
+
/** ECDH-wrapped private source sent to selected nodes. */
|
|
82
41
|
interface EncKeyBundle {
|
|
83
42
|
ephemeralPub: string;
|
|
84
43
|
nonceSym: string;
|
|
@@ -119,7 +78,7 @@ interface SchnorrSignature {
|
|
|
119
78
|
interface AttestationPayload {
|
|
120
79
|
/** 32-byte packed value, hex — the bytes covered by the signature. */
|
|
121
80
|
value: string;
|
|
122
|
-
/** 32-byte source id, hex (`deriveSourceId(
|
|
81
|
+
/** 32-byte source id, hex (`deriveSourceId(source)`): the keccak256 of the source's canonical bytes. */
|
|
123
82
|
sourceId: string;
|
|
124
83
|
registryVersion: number;
|
|
125
84
|
signaturesRequired: number;
|
|
@@ -134,10 +93,16 @@ interface AttestationPayload {
|
|
|
134
93
|
interface Attestation {
|
|
135
94
|
payload: AttestationPayload;
|
|
136
95
|
signature: SchnorrSignature;
|
|
137
|
-
/** Human-readable value (not signed). */
|
|
96
|
+
/** Human-readable value, rendered from the signed value by the source's output (not signed). */
|
|
138
97
|
value: string;
|
|
139
98
|
/** Whether the value was freshly fetched this round. */
|
|
140
99
|
fresh: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* For a source with a `keccak256` output: the bytes that were hashed to `payload.value`, hex. The
|
|
102
|
+
* gateway does not store it, so this is its only copy; submitting the attestation to Solana passes
|
|
103
|
+
* it as the raw value (at most 256 bytes) so the feed stores the preimage's hash with its kind.
|
|
104
|
+
*/
|
|
105
|
+
valuePreimage?: string;
|
|
141
106
|
}
|
|
142
107
|
/**
|
|
143
108
|
* Registry selection policy as advertised by the gateway's `GET /v1/nodes`.
|
|
@@ -253,4 +218,5 @@ declare function signerFromKeypair(keypair: SolanaKeypair): Signer;
|
|
|
253
218
|
/** Resolve the gateway auth signer for a Molpha wallet, if available. */
|
|
254
219
|
declare function gatewaySignerFromWallet(wallet: Wallet): Signer | undefined;
|
|
255
220
|
|
|
256
|
-
export {
|
|
221
|
+
export { gatewaySignerFromWallet as n, signerFromKeypair as s };
|
|
222
|
+
export type { AssetDomain as A, EvmSigner as E, MolphaWallet as M, Node as N, RegistrySelectionConfig as R, Signer as S, UpstreamQuote as U, UpstreamTerms as a, SourcePaymentOptions as b, NodeKeyVerifier as c, NodesInfo as d, Attestation as e, SolanaAccountMeta as f, SolanaConnection as g, SolanaAddress as h, NodeKeyVerifierArgs as i, AttestationPayload as j, EncKeyBundle as k, RegistryInfo as l, SchnorrSignature as m, SolanaKeypair as o };
|
package/idl/molpha.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"address": "
|
|
2
|
+
"address": "chivcFQgxzwkpLvW41PV431HQ4dYpaW3povQH3AdpQt",
|
|
3
3
|
"metadata": {
|
|
4
4
|
"name": "molpha",
|
|
5
5
|
"version": "0.1.0",
|
|
@@ -1468,7 +1468,7 @@
|
|
|
1468
1468
|
"docs": [
|
|
1469
1469
|
"This program. Its account names the ProgramData account holding the upgrade authority."
|
|
1470
1470
|
],
|
|
1471
|
-
"address": "
|
|
1471
|
+
"address": "chivcFQgxzwkpLvW41PV431HQ4dYpaW3povQH3AdpQt"
|
|
1472
1472
|
},
|
|
1473
1473
|
{
|
|
1474
1474
|
"name": "program_data"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molpha/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-dev-20261022065307",
|
|
4
4
|
"description": "Molpha Consumer SDK — subscribe, request signed data from the gateway, submit attestations and read on-chain feeds.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -39,15 +39,35 @@
|
|
|
39
39
|
"types": "./dist/utils.d.ts"
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"select-profile": "tsx scripts/select-profile.ts",
|
|
44
|
+
"prebuild": "pnpm select-profile",
|
|
45
|
+
"build": "tsup",
|
|
46
|
+
"pretypecheck": "pnpm select-profile",
|
|
47
|
+
"typecheck": "tsc --noEmit",
|
|
48
|
+
"pretest": "pnpm select-profile",
|
|
49
|
+
"test": "vitest run",
|
|
50
|
+
"test:watch": "vitest",
|
|
51
|
+
"clean": "rm -rf dist",
|
|
52
|
+
"lint": "eslint .",
|
|
53
|
+
"lint:fix": "eslint . --fix",
|
|
54
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
55
|
+
"changeset": "changeset",
|
|
56
|
+
"changeset:add-empty": "changeset add --empty",
|
|
57
|
+
"version-packages": "changeset version",
|
|
58
|
+
"e2e-demo": "tsx scripts/molpha-consumer-e2e-demo.ts",
|
|
59
|
+
"release": "pnpm build && changeset publish",
|
|
60
|
+
"release:dev": "changeset version --snapshot dev && pnpm build && npm publish --tag dev"
|
|
61
|
+
},
|
|
42
62
|
"dependencies": {
|
|
43
|
-
"@noble/ciphers": "^2.
|
|
44
|
-
"@noble/curves": "^2.
|
|
45
|
-
"@noble/hashes": "^2.
|
|
46
|
-
"@solana/kit": "^
|
|
47
|
-
"canonicalize": "^
|
|
63
|
+
"@noble/ciphers": "^2.4.0",
|
|
64
|
+
"@noble/curves": "^2.4.0",
|
|
65
|
+
"@noble/hashes": "^2.4.0",
|
|
66
|
+
"@solana/kit": "^8.5.0",
|
|
67
|
+
"canonicalize": "^5.1.0"
|
|
48
68
|
},
|
|
49
69
|
"peerDependencies": {
|
|
50
|
-
"@anchor-lang/core": "^1.1
|
|
70
|
+
"@anchor-lang/core": "^1.2.1",
|
|
51
71
|
"bn.js": "^5.1.2"
|
|
52
72
|
},
|
|
53
73
|
"peerDependenciesMeta": {
|
|
@@ -59,34 +79,32 @@
|
|
|
59
79
|
}
|
|
60
80
|
},
|
|
61
81
|
"devDependencies": {
|
|
62
|
-
"@anchor-lang/core": "^1.1
|
|
63
|
-
"@changesets/cli": "^
|
|
82
|
+
"@anchor-lang/core": "^1.2.1",
|
|
83
|
+
"@changesets/cli": "^3.0.3",
|
|
84
|
+
"@eslint/js": "^10.0.1",
|
|
64
85
|
"@types/bn.js": "^5.2.0",
|
|
65
86
|
"bn.js": "^5.2.3",
|
|
66
|
-
"
|
|
87
|
+
"eslint": "^10.0.1",
|
|
88
|
+
"eslint-config-prettier": "^10.1.8",
|
|
89
|
+
"globals": "^17.13.0",
|
|
90
|
+
"prettier": "^3.9.10",
|
|
91
|
+
"tsup": "^9.0.0",
|
|
67
92
|
"tsx": "^4.22.4",
|
|
68
93
|
"typescript": "^5.7.3",
|
|
94
|
+
"typescript-eslint": "^8.72.0",
|
|
69
95
|
"viem": "^2.52.2",
|
|
70
|
-
"vitest": "^
|
|
96
|
+
"vitest": "^5.0.5"
|
|
97
|
+
},
|
|
98
|
+
"pnpm": {
|
|
99
|
+
"overrides": {
|
|
100
|
+
"rpc-websockets>uuid": "11.1.1",
|
|
101
|
+
"ws": ">=8.21.0",
|
|
102
|
+
"js-yaml": ">=4.2.0",
|
|
103
|
+
"esbuild": ">=0.28.1"
|
|
104
|
+
}
|
|
71
105
|
},
|
|
72
106
|
"engines": {
|
|
73
107
|
"node": ">=20.19.0"
|
|
74
108
|
},
|
|
75
|
-
"
|
|
76
|
-
|
|
77
|
-
"prebuild": "pnpm select-profile",
|
|
78
|
-
"build": "tsup",
|
|
79
|
-
"pretypecheck": "pnpm select-profile",
|
|
80
|
-
"typecheck": "tsc --noEmit",
|
|
81
|
-
"pretest": "pnpm select-profile",
|
|
82
|
-
"test": "vitest run",
|
|
83
|
-
"test:watch": "vitest",
|
|
84
|
-
"clean": "rm -rf dist",
|
|
85
|
-
"changeset": "changeset",
|
|
86
|
-
"changeset:add-empty": "changeset add --empty",
|
|
87
|
-
"version-packages": "changeset version",
|
|
88
|
-
"e2e-demo": "tsx scripts/molpha-consumer-e2e-demo.ts",
|
|
89
|
-
"release": "pnpm build && changeset publish",
|
|
90
|
-
"release:dev": "changeset version --snapshot dev && pnpm build && npm publish --tag dev"
|
|
91
|
-
}
|
|
92
|
-
}
|
|
109
|
+
"packageManager": "pnpm@10.15.1+sha512.34e538c329b5553014ca8e8f4535997f96180a1d0f614339357449935350d924e22f8614682191264ec33d1462ac21561aff97f6bb18065351c162c7e8f6de67"
|
|
110
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/solana/kit.ts"],"names":[],"mappings":";;;;AAaO,IAAM,qBAAA,GAAwB,QAAQ,6CAA6C;AACnF,IAAM,gCA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,oBAAA,CAAqB,mBAAA,CAAoB,EAAE,eAAe,CAAA;AACxE;AAEO,SAAS,qBAAqB,SAAA,EAAsC;AACzE,EAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,aAAA,CAAc,SAAS,CAAA;AAC7C","file":"chunk-H77BBZOL.js","sourcesContent":["import { web3 } from \"@anchor-lang/core\";\nimport { address, getAddressDecoder, getAddressEncoder, type Address } from \"@solana/kit\";\n\nexport type SolanaAddress = Address | string | InstanceType<typeof web3.PublicKey>;\nexport type SolanaConnection = InstanceType<typeof web3.Connection>;\nexport type SolanaKeypair = InstanceType<typeof web3.Keypair>;\nexport type SolanaInstruction = InstanceType<typeof web3.TransactionInstruction>;\nexport type SolanaAccountMeta = {\n pubkey: InstanceType<typeof web3.PublicKey>;\n isSigner: boolean;\n isWritable: boolean;\n};\n\nexport const TOKEN_PROGRAM_ADDRESS = address(\"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\");\nexport const ASSOCIATED_TOKEN_PROGRAM_ADDRESS = address(\n \"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL\",\n);\nexport const SYSTEM_PROGRAM_ADDRESS = address(\"11111111111111111111111111111111\");\n\nconst addressEncoder = getAddressEncoder();\nconst addressDecoder = getAddressDecoder();\n\nexport function toSolanaAddress(value: SolanaAddress): Address {\n return address(typeof value === \"string\" ? value : value.toBase58());\n}\n\nexport function toPublicKey(value: SolanaAddress): InstanceType<typeof web3.PublicKey> {\n return value instanceof web3.PublicKey ? value : new web3.PublicKey(value);\n}\n\nexport function addressBytes(value: SolanaAddress): Uint8Array {\n return Uint8Array.from(addressEncoder.encode(toSolanaAddress(value)));\n}\n\n/** Base58 `Address` from 32 raw bytes (e.g. a `Registry.nodes[i]` entry). */\nexport function addressFromBytes(bytes: Uint8Array): Address {\n return addressDecoder.decode(bytes);\n}\n\nexport function findProgramAddressSync(\n seeds: Uint8Array[],\n programAddress: SolanaAddress,\n): Address {\n const [pda] = web3.PublicKey.findProgramAddressSync(seeds, toPublicKey(programAddress));\n return toSolanaAddress(pda);\n}\n\nexport function findProgramPublicKeySync(\n seeds: Uint8Array[],\n programAddress: SolanaAddress,\n): InstanceType<typeof web3.PublicKey> {\n const [pda] = web3.PublicKey.findProgramAddressSync(seeds, toPublicKey(programAddress));\n return pda;\n}\n\nexport function getAssociatedTokenAddressSync(\n mint: SolanaAddress,\n owner: SolanaAddress,\n tokenProgram: SolanaAddress = TOKEN_PROGRAM_ADDRESS,\n): Address {\n return findProgramAddressSync(\n [addressBytes(owner), addressBytes(tokenProgram), addressBytes(mint)],\n ASSOCIATED_TOKEN_PROGRAM_ADDRESS,\n );\n}\n\nexport function setComputeUnitLimit(units: number): SolanaInstruction {\n return web3.ComputeBudgetProgram.setComputeUnitLimit({ units });\n}\n\nexport function setComputeUnitPrice(microLamports: number): SolanaInstruction {\n return web3.ComputeBudgetProgram.setComputeUnitPrice({ microLamports });\n}\n\nexport function keypairFromSecretKey(secretKey: Uint8Array): SolanaKeypair {\n return web3.Keypair.fromSecretKey(secretKey);\n}\n\nexport function generateKeypair(): SolanaKeypair {\n return web3.Keypair.generate();\n}\n"]}
|