@molpha/sdk 0.2.0-dev-20261006113121 → 0.2.0-dev-20261007162054
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 +19 -10
- package/dist/index.d.ts +2 -2
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/{wallet--IGHoCtG.d.ts → wallet-DGe_pi93.d.ts} +11 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
# @molpha/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@molpha/sdk)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
|
|
6
|
+
TypeScript SDK for **[Molpha](https://molpha.io)**, a pull-based oracle protocol. Molpha nodes
|
|
7
|
+
fetch an API result, sign it once with a threshold signature, and the same signed attestation can be
|
|
8
|
+
verified on **Solana, EVM and Starknet**. This SDK is for data consumers and feed owners, and runs in
|
|
9
|
+
the browser and in Node.js.
|
|
10
|
+
|
|
11
|
+
Links: [molpha.io](https://molpha.io) · [GitHub](https://github.com/Molpha/sdk) · [npm](https://www.npmjs.com/package/@molpha/sdk)
|
|
4
12
|
|
|
5
13
|
Use it to:
|
|
6
14
|
|
|
@@ -57,17 +65,19 @@ The preimage is 141 bytes (32 + 32 + 32 + 4 + 1 + 8 + 32).
|
|
|
57
65
|
## Install
|
|
58
66
|
|
|
59
67
|
```bash
|
|
60
|
-
|
|
68
|
+
npm install @molpha/sdk @anchor-lang/core bn.js
|
|
69
|
+
# or: pnpm add @molpha/sdk @anchor-lang/core bn.js
|
|
70
|
+
# or: yarn add @molpha/sdk @anchor-lang/core bn.js
|
|
61
71
|
```
|
|
62
72
|
|
|
63
|
-
|
|
73
|
+
`@anchor-lang/core` and `bn.js` are optional peer dependencies. Install them if you use the Solana / Anchor path (as in the examples below). Gateway-only or EVM/Starknet-only apps can skip them. Runtime dependencies installed automatically are `@solana/kit`, `@noble/*` and `canonicalize`.
|
|
74
|
+
|
|
75
|
+
For the pre-release channel (the `dev` gateway and the matching dev Solana program; may change without notice):
|
|
64
76
|
|
|
65
77
|
```bash
|
|
66
|
-
|
|
78
|
+
npm install @molpha/sdk@dev
|
|
67
79
|
```
|
|
68
80
|
|
|
69
|
-
Runtime dependencies include `@solana/kit`, `@anchor-lang/core`, and `@noble/*`. `bn.js` is an optional peer dependency (used by the Solana / Anchor path).
|
|
70
|
-
|
|
71
81
|
### npm tags and deployment defaults
|
|
72
82
|
|
|
73
83
|
Defaults are baked at publish time from `config/deployments.json` (`MOLPHA_SDK_PROFILE`). Override at runtime with `endpoints`, `programId`, and `idl`.
|
|
@@ -208,7 +218,6 @@ nobody can pick a committee by picking a time.
|
|
|
208
218
|
A 400 saying the `registryVersion` is not the current one (a cached context, or a registry roll between your read and the request) is the exception: the SDK reads the registry afresh and retries once, without spending an attempt.
|
|
209
219
|
|
|
210
220
|
`timeoutMs` defaults to 35 s, above the gateway's own wait for a round (`roundTimeoutSeconds` in `/v1/info`, 30 s by default). A shorter timeout abandons a round the gateway is still running, and the retry then starts another. A source that cannot be fetched is reported as soon as enough nodes have failed (usually well under a second), not after the wait.
|
|
211
|
-
- Private API secrets are encrypted for every node of the registry (the committee is unknown until the gateway stamps the round); the gateway forwards only the selected nodes' envelopes. `verifyNodeKeys` therefore authenticates all of them.
|
|
212
221
|
|
|
213
222
|
## Wallet
|
|
214
223
|
|
|
@@ -271,7 +280,7 @@ import { walletFromKeypairFile } from "@molpha/sdk/utils";
|
|
|
271
280
|
|
|
272
281
|
const sdk = new MolphaSDK({
|
|
273
282
|
connection: new web3.Connection("https://api.devnet.solana.com", "confirmed"),
|
|
274
|
-
wallet: walletFromKeypairFile("~/.config/
|
|
283
|
+
wallet: walletFromKeypairFile("~/.config/solana/id.json"),
|
|
275
284
|
});
|
|
276
285
|
```
|
|
277
286
|
|
|
@@ -496,7 +505,7 @@ const result = await sdk.gateway.requestSignedData({
|
|
|
496
505
|
|
|
497
506
|
`MolphaSDK` wires `verifyNodeKeys` to `solana.verifyNodeKeysForPrivateApi`, which authenticates gateway node encryption keys against the on-chain `Node` accounts of the round's registry snapshot (`registry.nodes[index]`) before secrets are encrypted.
|
|
498
507
|
|
|
499
|
-
Secrets are encrypted into per-node envelopes. The gateway coordinates the round but should not receive plaintext API credentials. The encrypted plaintext is the canonical config (including `aggregation`) with secrets substituted.
|
|
508
|
+
Secrets are encrypted into per-node envelopes. The gateway coordinates the round but should not receive plaintext API credentials. Secrets are encrypted for every node of the registry (the committee is unknown until the gateway stamps the round), and the gateway forwards only the selected nodes' envelopes. `verifyNodeKeys` therefore authenticates all of them. The encrypted plaintext is the canonical config (including `aggregation`) with secrets substituted.
|
|
500
509
|
|
|
501
510
|
Private API access is still an active security-sensitive surface. Do not treat encrypted secret delivery as production-ready until gateway/node-side test vectors and validation are complete.
|
|
502
511
|
|
|
@@ -902,7 +911,7 @@ The facade wires the registry selection config resolver, gateway signer, subscri
|
|
|
902
911
|
|
|
903
912
|
## Status
|
|
904
913
|
|
|
905
|
-
|
|
914
|
+
Pre-1.0. The `latest` dist-tag is `0.1.0` (stable profile). Newer features described in this README (for example tolerance mode, `requestMany` and paywalled API sources) may be available only on the `dev` tag until the next stable release. See [CHANGELOG.md](./CHANGELOG.md).
|
|
906
915
|
|
|
907
916
|
Current scope:
|
|
908
917
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Address } from '@solana/kit';
|
|
2
2
|
import { Wallet, Idl, AnchorProvider } from '@anchor-lang/core';
|
|
3
|
-
import { U as UpstreamQuote, A as APIConfig, a as AssetDomain, b as UpstreamTerms, E as EvmSigner, S as Signer, c as SourcePaymentOptions, R as RegistrySelectionConfig, N as Node, d as NodeKeyVerifier, e as NodesInfo, f as Attestation, g as SolanaAccountMeta, h as SolanaConnection, i as SolanaAddress, j as NodeKeyVerifierArgs, k as AggregationConfig, M as MolphaWallet } from './wallet
|
|
4
|
-
export { l as AttestationPayload, m as EncKeyBundle, n as NumericConfig, o as RegistryInfo, p as SchnorrSignature, q as gatewaySignerFromWallet, s as signerFromKeypair } from './wallet
|
|
3
|
+
import { U as UpstreamQuote, A as APIConfig, a as AssetDomain, b as UpstreamTerms, E as EvmSigner, S as Signer, c as SourcePaymentOptions, R as RegistrySelectionConfig, N as Node, d as NodeKeyVerifier, e as NodesInfo, f as Attestation, g as SolanaAccountMeta, h as SolanaConnection, i as SolanaAddress, j as NodeKeyVerifierArgs, k as AggregationConfig, M as MolphaWallet } from './wallet-DGe_pi93.js';
|
|
4
|
+
export { l as AttestationPayload, m as EncKeyBundle, n as NumericConfig, o as RegistryInfo, p as SchnorrSignature, q as gatewaySignerFromWallet, s as signerFromKeypair } from './wallet-DGe_pi93.js';
|
|
5
5
|
import BN from 'bn.js';
|
|
6
6
|
|
|
7
7
|
/**
|
package/dist/index.js
CHANGED
|
@@ -586,6 +586,9 @@ var NETWORKS = {
|
|
|
586
586
|
base: { chainId: 8453, usdc: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" },
|
|
587
587
|
"base-sepolia": { chainId: 84532, usdc: "0x036CbD53842c5426634e7929541eC2318f3dCF7e" }
|
|
588
588
|
};
|
|
589
|
+
function newPaymentId() {
|
|
590
|
+
return `pay_${bytesToHex0x(randomBytes(16)).slice(2)}`;
|
|
591
|
+
}
|
|
589
592
|
var UpstreamPaymentRequiredError = class extends Error {
|
|
590
593
|
constructor(quote, message) {
|
|
591
594
|
super(
|
|
@@ -645,8 +648,11 @@ function selectTerms(envelope, resource, assetDomain) {
|
|
|
645
648
|
}
|
|
646
649
|
const payTo = String(supported.payTo ?? "");
|
|
647
650
|
if (!payTo) throw new Error(`Source ${resource} omitted payTo`);
|
|
651
|
+
const declared = envelope.extensions?.["payment-identifier"];
|
|
652
|
+
const paymentIdentifier = declared && typeof declared === "object" && declared.info && typeof declared.info === "object" ? { info: declared.info, schema: declared.schema } : void 0;
|
|
648
653
|
return {
|
|
649
654
|
x402Version: version,
|
|
655
|
+
paymentIdentifier,
|
|
650
656
|
// Echoed verbatim in the signed payload, so it must stay the source's own object.
|
|
651
657
|
requirements: supported,
|
|
652
658
|
network: String(supported.network),
|
|
@@ -742,6 +748,15 @@ async function signSourcePayments(terms, signer, count) {
|
|
|
742
748
|
accepted: terms.requirements,
|
|
743
749
|
payload: { signature, authorization }
|
|
744
750
|
};
|
|
751
|
+
if (terms.x402Version === 2 && terms.paymentIdentifier) {
|
|
752
|
+
const { info, schema } = terms.paymentIdentifier;
|
|
753
|
+
payload.extensions = {
|
|
754
|
+
"payment-identifier": {
|
|
755
|
+
info: { ...info, id: newPaymentId() },
|
|
756
|
+
...schema !== void 0 ? { schema } : {}
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
}
|
|
745
760
|
payments.push(bytesToBase64(utf8(JSON.stringify(payload))));
|
|
746
761
|
}
|
|
747
762
|
return payments;
|