@molpha/sdk 0.1.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.
@@ -0,0 +1,14 @@
1
+ export { Wallet } from '@anchor-lang/core';
2
+ import { S as Signer, h as SolanaKeypair, M as MolphaWallet } from './wallet-CbpYQO4l.js';
3
+ import '@solana/kit';
4
+
5
+ /** Load a Solana CLI keypair JSON file (array of 64 bytes) into a `Keypair`. */
6
+ declare function loadKeypair(path: string): SolanaKeypair;
7
+ /** Anchor `Wallet` backed by a keypair file (gateway auth derived from the same key). */
8
+ declare function walletFromKeypairFile(path: string): MolphaWallet;
9
+ /** @deprecated Use `walletFromKeypairFile`. */
10
+ declare const nodeWalletFromFile: typeof walletFromKeypairFile;
11
+ /** @deprecated Use `walletFromKeypairFile` — gateway auth is derived from the same keypair. */
12
+ declare function keypairFileSigner(path: string): Signer;
13
+
14
+ export { MolphaWallet, keypairFileSigner, loadKeypair, nodeWalletFromFile, walletFromKeypairFile };
package/dist/utils.js ADDED
@@ -0,0 +1,20 @@
1
+ import { keypairFromSecretKey, signerFromKeypair } from './chunk-MFELBWSL.js';
2
+ import { readFileSync } from 'fs';
3
+ import { Wallet } from '@anchor-lang/core';
4
+ export { Wallet } from '@anchor-lang/core';
5
+
6
+ function loadKeypair(path) {
7
+ const raw = JSON.parse(readFileSync(path, "utf-8"));
8
+ return keypairFromSecretKey(Uint8Array.from(raw));
9
+ }
10
+ function walletFromKeypairFile(path) {
11
+ return new Wallet(loadKeypair(path));
12
+ }
13
+ var nodeWalletFromFile = walletFromKeypairFile;
14
+ function keypairFileSigner(path) {
15
+ return signerFromKeypair(loadKeypair(path));
16
+ }
17
+
18
+ export { keypairFileSigner, loadKeypair, nodeWalletFromFile, walletFromKeypairFile };
19
+ //# sourceMappingURL=utils.js.map
20
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils.ts"],"names":[],"mappings":";;;;;AAWO,SAAS,YAAY,IAAA,EAA6B;AACvD,EAAA,MAAM,MAAM,IAAA,CAAK,KAAA,CAAM,YAAA,CAAa,IAAA,EAAM,OAAO,CAAC,CAAA;AAClD,EAAA,OAAO,oBAAA,CAAqB,UAAA,CAAW,IAAA,CAAK,GAAG,CAAC,CAAA;AAClD;AAGO,SAAS,sBAAsB,IAAA,EAA4B;AAChE,EAAA,OAAO,IAAI,MAAA,CAAO,WAAA,CAAY,IAAI,CAAC,CAAA;AACrC;AAGO,IAAM,kBAAA,GAAqB;AAG3B,SAAS,kBAAkB,IAAA,EAAsB;AACtD,EAAA,OAAO,iBAAA,CAAkB,WAAA,CAAY,IAAI,CAAC,CAAA;AAC5C","file":"utils.js","sourcesContent":["/**\n * `@molpha/sdk/utils` — Node.js-only helpers (fs + keypair files). Kept out of the main\n * entry so browser bundles never pull in `fs`.\n */\nimport { readFileSync } from \"node:fs\";\nimport { Wallet } from \"@anchor-lang/core\";\nimport type { Signer } from \"./core/types.js\";\nimport { keypairFromSecretKey, type SolanaKeypair } from \"./solana/kit.js\";\nimport { signerFromKeypair, type MolphaWallet } from \"./wallet.js\";\n\n/** Load a Solana CLI keypair JSON file (array of 64 bytes) into a `Keypair`. */\nexport function loadKeypair(path: string): SolanaKeypair {\n const raw = JSON.parse(readFileSync(path, \"utf-8\")) as number[];\n return keypairFromSecretKey(Uint8Array.from(raw));\n}\n\n/** Anchor `Wallet` backed by a keypair file (gateway auth derived from the same key). */\nexport function walletFromKeypairFile(path: string): MolphaWallet {\n return new Wallet(loadKeypair(path));\n}\n\n/** @deprecated Use `walletFromKeypairFile`. */\nexport const nodeWalletFromFile = walletFromKeypairFile;\n\n/** @deprecated Use `walletFromKeypairFile` — gateway auth is derived from the same keypair. */\nexport function keypairFileSigner(path: string): Signer {\n return signerFromKeypair(loadKeypair(path));\n}\n\nexport { Wallet };\nexport type { MolphaWallet };\n"]}
@@ -0,0 +1,122 @@
1
+ import { web3, Wallet } from '@anchor-lang/core';
2
+ import { Address } from '@solana/kit';
3
+
4
+ /**
5
+ * Public protocol types (spec §8). Kept dependency-free so they can be imported
6
+ * from any entry point.
7
+ */
8
+ /** A registered oracle node as returned by the gateway. */
9
+ interface Node {
10
+ index: number;
11
+ peerId: string;
12
+ address: string;
13
+ /** Node secp256k1 public key (hex). Used for ECDH config encryption. */
14
+ signingKey: string;
15
+ }
16
+ /** Selected node-key material that must be authenticated before private API encryption. */
17
+ interface NodeKeyVerifierArgs {
18
+ /** 32-byte feed id, hex. */
19
+ feedId: string;
20
+ /** On-chain registry version the gateway round is bound to. */
21
+ registryVersion: number;
22
+ /** Canonical timestamp used to derive the selected indexes. */
23
+ timestamp: number;
24
+ /** Selected node indexes derived from the round bitmap, ascending. */
25
+ selectedIndexes: readonly number[];
26
+ /** Gateway-provided selected nodes whose keys must be authenticated. */
27
+ selectedNodes: readonly Node[];
28
+ }
29
+ /**
30
+ * Authenticates selected gateway node encryption keys. Throwing fails the
31
+ * private API request before secrets are encrypted or posted.
32
+ */
33
+ type NodeKeyVerifier = (args: NodeKeyVerifierArgs) => void | Promise<void>;
34
+ /** The off-chain API definition a feed resolves. */
35
+ interface APIConfig {
36
+ url: string;
37
+ method?: "GET" | "POST" | "PUT";
38
+ headers?: Record<string, string>;
39
+ /** Expression that extracts the value from the HTTP response. */
40
+ responseParser: string;
41
+ /** Optional expression applied to the parsed value before packing. */
42
+ valueTransform?: string;
43
+ }
44
+ /** ECDH-wrapped API config payload sent to selected nodes. */
45
+ interface EncKeyBundle {
46
+ ephemeralPub: string;
47
+ nonceSym: string;
48
+ ciphertext: string;
49
+ /** nodeIndex -> hex(nonceEnv || wrappedSymKey) */
50
+ envelopes: Record<string, string>;
51
+ }
52
+ /** Signs a message and returns a 64-byte ed25519 signature. */
53
+ type Signer = (message: Uint8Array) => Promise<Uint8Array>;
54
+ /**
55
+ * On-chain registry fields a gateway selection round is bound to. Fetched from
56
+ * `RegistryState` (`current_version`, `redundancy_buffer`).
57
+ */
58
+ interface RegistrySelectionConfig {
59
+ registryVersion: number;
60
+ /** Selection padding: `min(signaturesRequired + redundancyBuffer, nodeCount)`. */
61
+ redundancyBuffer: number;
62
+ }
63
+ /**
64
+ * Aggregate Schnorr signature in the commitment-address form the shipped program
65
+ * verifies (`MOLPHA_MESSAGE_V1`). The legacy `(rx, ryParity)` fields are gone.
66
+ */
67
+ interface SchnorrSignature {
68
+ /** 32-byte scalar, hex. */
69
+ s: string;
70
+ /** 20-byte EVM-style commitment address, hex. */
71
+ commitmentAddr: string;
72
+ /** 32-byte big-endian signers bitmap, hex. */
73
+ signersBitmap: string;
74
+ }
75
+ /** A completed gateway round, ready to submit on-chain. */
76
+ interface DataUpdateResult {
77
+ feedId: string;
78
+ /** Human-readable value. */
79
+ value: string;
80
+ /** 32-byte packed value, hex. */
81
+ valuePacked: string;
82
+ /** canonicalTimestamp (seconds). */
83
+ timestamp: number;
84
+ registryVersion: number;
85
+ signaturesRequired: number;
86
+ /** 32-byte big-endian bitmap, hex. */
87
+ signersBitmap: string;
88
+ /** 32-byte scalar, hex. */
89
+ s: string;
90
+ /** 20-byte commitment address, hex. */
91
+ commitmentAddr: string;
92
+ /** Whether the value was freshly fetched this round. */
93
+ fresh: boolean;
94
+ }
95
+
96
+ type SolanaAddress = Address | string | InstanceType<typeof web3.PublicKey>;
97
+ type SolanaConnection = InstanceType<typeof web3.Connection>;
98
+ type SolanaKeypair = InstanceType<typeof web3.Keypair>;
99
+ type SolanaAccountMeta = {
100
+ pubkey: InstanceType<typeof web3.PublicKey>;
101
+ isSigner: boolean;
102
+ isWritable: boolean;
103
+ };
104
+
105
+ /**
106
+ * Unified wallet surface: Anchor txs + optional gateway authSig signing.
107
+ */
108
+
109
+ /** Anchor `Wallet` plus optional gateway auth override. */
110
+ type MolphaWallet = Wallet & {
111
+ /**
112
+ * Signs gateway `authMessage` payloads. When omitted, derived from Anchor
113
+ * `Wallet.payer` when the keypair secret is available (Node `Wallet`, etc.).
114
+ */
115
+ signAuthMessage?: Signer;
116
+ };
117
+ /** ed25519 gateway signer from a Solana keypair's 32-byte seed. */
118
+ declare function signerFromKeypair(keypair: SolanaKeypair): Signer;
119
+ /** Resolve the gateway auth signer for a Molpha wallet, if available. */
120
+ declare function gatewaySignerFromWallet(wallet: Wallet): Signer | undefined;
121
+
122
+ export { type APIConfig as A, type DataUpdateResult as D, type EncKeyBundle as E, type MolphaWallet as M, type NodeKeyVerifier as N, type RegistrySelectionConfig as R, type Signer as S, type Node as a, type SolanaConnection as b, type SolanaAddress as c, type NodeKeyVerifierArgs as d, type SolanaAccountMeta as e, type SchnorrSignature as f, gatewaySignerFromWallet as g, type SolanaKeypair as h, signerFromKeypair as s };
package/idl/index.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { Idl } from "@anchor-lang/core";
2
+ import idlJson from "./molpha.json" with { type: "json" };
3
+
4
+ /**
5
+ * Vendored Molpha Anchor IDL (`target/idl/molpha.json` from the program repo).
6
+ *
7
+ * Re-exported as `MOLPHA_IDL` and used as the default in `MolphaSDK` /
8
+ * `MolphaSolanaClient.create`. Pass `idl` / `programId` only when pinning a
9
+ * different deployment. Keep this copy aligned with the on-chain program you target.
10
+ */
11
+ export const MOLPHA_IDL = idlJson as Idl;
12
+
13
+ /** Program address baked into the vendored IDL. */
14
+ export const MOLPHA_PROGRAM_ADDRESS: string = idlJson.address;