@molpha/sdk 0.2.0-dev-20261005191253 → 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 +34 -8
- package/dist/index.d.ts +27 -16
- package/dist/index.js +22 -7
- 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/idl/profiles/dev/molpha.json +7841 -0
- package/idl/profiles/stable/molpha.json +5563 -0
- package/package.json +5 -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,10 +65,29 @@ 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
|
|
71
|
+
```
|
|
72
|
+
|
|
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):
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
npm install @molpha/sdk@dev
|
|
61
79
|
```
|
|
62
80
|
|
|
63
|
-
|
|
81
|
+
### npm tags and deployment defaults
|
|
82
|
+
|
|
83
|
+
Defaults are baked at publish time from `config/deployments.json` (`MOLPHA_SDK_PROFILE`). Override at runtime with `endpoints`, `programId`, and `idl`.
|
|
84
|
+
|
|
85
|
+
| npm dist-tag | Profile | Default gateway | Solana program | EVM / Starknet |
|
|
86
|
+
|---|---|---|---|---|
|
|
87
|
+
| `latest` | `stable` | `https://gateway.molpha.io/` | `MoLFGDpFoVnQgwbkTNScKPohCxhbfd61JjFrnotuwzh` | Documented CREATE2 / Sepolia addresses |
|
|
88
|
+
| `dev` | `dev` | `https://dev-gateway.molpha.io/` | `chivcFQgxzwkpLvW41PV431HQ4dYpaW3povQH3AdpQt` | Provisional until redeploy (`MOLPHA_DEV_VERIFIERS_PROVISIONAL`); falls back to stable addresses |
|
|
89
|
+
|
|
90
|
+
Inspect the active profile via `MOLPHA_SDK_PROFILE` and `MOLPHA_DEV_VERIFIERS_PROVISIONAL`. Local builds: `MOLPHA_SDK_PROFILE=stable pnpm build` or `MOLPHA_SDK_PROFILE=dev pnpm build` (default `dev`).
|
|
64
91
|
|
|
65
92
|
| Import | Use |
|
|
66
93
|
|---|---|
|
|
@@ -191,7 +218,6 @@ nobody can pick a committee by picking a time.
|
|
|
191
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.
|
|
192
219
|
|
|
193
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.
|
|
194
|
-
- 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.
|
|
195
221
|
|
|
196
222
|
## Wallet
|
|
197
223
|
|
|
@@ -254,7 +280,7 @@ import { walletFromKeypairFile } from "@molpha/sdk/utils";
|
|
|
254
280
|
|
|
255
281
|
const sdk = new MolphaSDK({
|
|
256
282
|
connection: new web3.Connection("https://api.devnet.solana.com", "confirmed"),
|
|
257
|
-
wallet: walletFromKeypairFile("~/.config/
|
|
283
|
+
wallet: walletFromKeypairFile("~/.config/solana/id.json"),
|
|
258
284
|
});
|
|
259
285
|
```
|
|
260
286
|
|
|
@@ -479,7 +505,7 @@ const result = await sdk.gateway.requestSignedData({
|
|
|
479
505
|
|
|
480
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.
|
|
481
507
|
|
|
482
|
-
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.
|
|
483
509
|
|
|
484
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.
|
|
485
511
|
|
|
@@ -885,7 +911,7 @@ The facade wires the registry selection config resolver, gateway signer, subscri
|
|
|
885
911
|
|
|
886
912
|
## Status
|
|
887
913
|
|
|
888
|
-
|
|
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).
|
|
889
915
|
|
|
890
916
|
Current scope:
|
|
891
917
|
|
|
@@ -907,7 +933,7 @@ Known limitations:
|
|
|
907
933
|
- production deployments should use authenticated gateway requests;
|
|
908
934
|
- testnet verifier addresses may change between protocol releases.
|
|
909
935
|
|
|
910
|
-
Solana paths such as selection bitmap and `submit_attestation` remaining-accounts resolution are aligned with the
|
|
936
|
+
Solana paths such as selection bitmap and `submit_attestation` remaining-accounts resolution are aligned with the IDL selected by the active deployment profile (`idl/profiles/{stable,dev}/molpha.json`).
|
|
911
937
|
|
|
912
938
|
## Develop
|
|
913
939
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
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
|
+
/**
|
|
8
|
+
* GENERATED by `scripts/select-profile.ts` — do not edit.
|
|
9
|
+
* Profile: dev
|
|
10
|
+
* EVM/Starknet verifier addresses are unset until the Attestation-interface redeploy. Codegen falls back to stable addresses and sets MOLPHA_DEV_VERIFIERS_PROVISIONAL.
|
|
11
|
+
*/
|
|
12
|
+
declare const MOLPHA_SDK_PROFILE: "dev";
|
|
13
|
+
declare const DEFAULT_GATEWAY_ENDPOINT = "https://dev-gateway.molpha.io/";
|
|
14
|
+
declare const MOLPHA_PROGRAM_ID = "chivcFQgxzwkpLvW41PV431HQ4dYpaW3povQH3AdpQt";
|
|
15
|
+
declare const MOLPHA_VERIFIER_ADDRESS: "0xE1fd792b7E54e0C8F0Cd1c8055E446ff36d233eB";
|
|
16
|
+
declare const MOLPHA_VERIFIER_STARKNET_SEPOLIA: "0x0378df4dbecf8f0c7daa801282932f7011c7a5e5773bab9eaf68f5fa5e7530ef";
|
|
17
|
+
/** True when the active profile has unset EVM/Starknet addresses (dev falls back to stable). */
|
|
18
|
+
declare const MOLPHA_DEV_VERIFIERS_PROVISIONAL: true;
|
|
19
|
+
|
|
7
20
|
/**
|
|
8
21
|
* Gateway on-chain identity. The request-auth hash binds the Gateway PDA
|
|
9
22
|
* (`["molpha_gateway", gatewayAuthority]`), so the client must know which gateway it is
|
|
@@ -260,8 +273,7 @@ type RetryCause = {
|
|
|
260
273
|
* `failures` is the number of attempts that have failed so far (1 after the first).
|
|
261
274
|
*/
|
|
262
275
|
declare function retryDelayMs(cause: RetryCause, failures: number, nowMs: number, tickMs: number, random?: () => number): number;
|
|
263
|
-
|
|
264
|
-
declare const DEFAULT_GATEWAY_ENDPOINT = "https://dev-gateway.molpha.io/";
|
|
276
|
+
|
|
265
277
|
/** Thrown for terminal gateway errors (400/401) — never retried. */
|
|
266
278
|
declare class GatewayError extends Error {
|
|
267
279
|
readonly status?: number | undefined;
|
|
@@ -743,13 +755,6 @@ declare function deriveSourceId(apiConfig: APIConfig): Uint8Array;
|
|
|
743
755
|
/** Hex-encoded {@link deriveSourceId} (64 lowercase hex chars, no `0x`). */
|
|
744
756
|
declare function deriveSourceIdString(apiConfig: APIConfig): string;
|
|
745
757
|
|
|
746
|
-
/**
|
|
747
|
-
* Protocol-wide constants that must stay in sync with the vendored IDL. Kept as plain
|
|
748
|
-
* literals so gateway-only / browser bundles never pull in `idl/molpha.json`.
|
|
749
|
-
*/
|
|
750
|
-
/** Molpha program id (`idl/molpha.json` → `address`). Asserted equal in `test/gateway-auth.test.ts`. */
|
|
751
|
-
declare const MOLPHA_PROGRAM_ID = "chivcFQgxzwkpLvW41PV431HQ4dYpaW3povQH3AdpQt";
|
|
752
|
-
|
|
753
758
|
declare const utf8: (s: string) => Uint8Array;
|
|
754
759
|
declare const concatBytes: (...arrays: Uint8Array[]) => Uint8Array;
|
|
755
760
|
/** Lower-case hex, no `0x` prefix. */
|
|
@@ -1149,11 +1154,14 @@ declare const MOLPHA_VERIFIER_ABI: readonly [{
|
|
|
1149
1154
|
/**
|
|
1150
1155
|
* Deployed Molpha verifier contract address on EVM chains.
|
|
1151
1156
|
* Deployed via CREATE2 for the same address on every supported chain.
|
|
1157
|
+
*
|
|
1158
|
+
* Address comes from the active deployment profile (`config/deployments.json`).
|
|
1159
|
+
* When `MOLPHA_DEV_VERIFIERS_PROVISIONAL` is true, the value is a stable fallback
|
|
1160
|
+
* and should not be treated as the live Attestation-interface deployment.
|
|
1152
1161
|
*/
|
|
1162
|
+
|
|
1153
1163
|
/** Supported EVM testnet identifiers (chain selection only). */
|
|
1154
1164
|
type MolphaEvmNetwork = "evm-sepolia" | "arbitrum-sepolia" | "avalanche-fuji" | "bsc-testnet";
|
|
1155
|
-
/** CREATE2 Molpha verifier address — identical on all supported EVM chains. */
|
|
1156
|
-
declare const MOLPHA_VERIFIER_ADDRESS: "0xE1fd792b7E54e0C8F0Cd1c8055E446ff36d233eB";
|
|
1157
1165
|
|
|
1158
1166
|
/** EIP-712 domain of the token contract that will settle the authorization. */
|
|
1159
1167
|
interface Eip712Domain {
|
|
@@ -1290,11 +1298,14 @@ declare function parseEvmVerifyResult(result: string | {
|
|
|
1290
1298
|
|
|
1291
1299
|
/**
|
|
1292
1300
|
* Deployed Molpha verifier contract addresses on Starknet testnets.
|
|
1301
|
+
*
|
|
1302
|
+
* Address comes from the active deployment profile (`config/deployments.json`).
|
|
1303
|
+
* When `MOLPHA_DEV_VERIFIERS_PROVISIONAL` is true, the value is a stable fallback
|
|
1304
|
+
* and should not be treated as the live Attestation-interface deployment.
|
|
1293
1305
|
*/
|
|
1306
|
+
|
|
1294
1307
|
/** Supported Starknet testnet identifiers. */
|
|
1295
1308
|
type MolphaStarknetNetwork = "starknet-sepolia";
|
|
1296
|
-
/** Deployed verifier address on Starknet Sepolia. */
|
|
1297
|
-
declare const MOLPHA_VERIFIER_STARKNET_SEPOLIA: "0x0378df4dbecf8f0c7daa801282932f7011c7a5e5773bab9eaf68f5fa5e7530ef";
|
|
1298
1309
|
/** Network id -> deployed verifier address. */
|
|
1299
1310
|
declare const MOLPHA_VERIFIER_STARKNET_ADDRESSES: Record<MolphaStarknetNetwork, `0x${string}`>;
|
|
1300
1311
|
/** Resolve the deployed verifier address for a supported Starknet network. */
|
|
@@ -1581,4 +1592,4 @@ declare class MolphaSDK {
|
|
|
1581
1592
|
}>;
|
|
1582
1593
|
}
|
|
1583
1594
|
|
|
1584
|
-
export { APIConfig, AdaptiveLimiter, AggregationConfig, AggregationConfigError, AssetDomain, Attestation, type AttestationMessageFields, type BuildEvmVerifierArgsOptions, type BuildStarknetVerifierArgsOptions, type BulkFeed, type BulkOptions, type BulkResult, type CoalitionKey, DEFAULT_GATEWAY_ENDPOINT, DEFAULT_MAX_RETRIES, DEFAULT_ROUND_TIMEOUT_MS, EIP712_DOMAIN_TYPEHASH, type Eip712Domain, type EvmAttestation, type EvmAttestationPayload, type EvmSchnorrSignature, EvmSigner, type EvmVerifierArgs, type EvmVerifyResult, type FeedAccount, type GatewayEndpoint, type GatewayEndpointInput, GatewayError, type GatewayInfo, INT256_MAX, INT256_MIN, MESSAGE_PREFIX, MIN_TOLERANCE_SIGNATURES, MOLPHA_IDL, MOLPHA_PROGRAM_ADDRESS, MOLPHA_PROGRAM_ID, MOLPHA_VERIFIER_ABI, MOLPHA_VERIFIER_ADDRESS, MOLPHA_VERIFIER_STARKNET_ADDRESSES, MOLPHA_VERIFIER_STARKNET_SEPOLIA, type MolphaEvmNetwork, MolphaGateway, type MolphaGatewayOptions, MolphaSDK, type MolphaSDKOptions, MolphaSolanaClient, type MolphaStarknetNetwork, MolphaWallet, Node, NodeKeyVerifier, NodeKeyVerifierArgs, NodesInfo, type PlanId, type PlanInfo, PlanType, REQUEST_AUTH_DOMAIN, RegistrySelectionConfig, type RegistryStateView, type RegistryView, type RequestAuthFields, type RequestSignedDataOptions, type RetryCause, type RoundContext, SELECTION_WINDOW_MS, type Secp256k1KeyInput, Signer, SourcePaymentOptions, type StarknetAttestation, type StarknetAttestationPayload, type StarknetFeltLike, type StarknetSchnorrSignature, type StarknetVerifierArgs, type StarknetVerifyResult, type SubmitAttestationArgs, type SubmitAttestationOptions, SubmitFailedError, type SubmitResult, type SubscribeResult, type SubscriptionInfo, TRANSFER_WITH_AUTHORIZATION_TYPEHASH, type TransferAuthorization, UpstreamPaymentRequiredError, UpstreamQuote, UpstreamTerms, VERIFY_CODES, type VerifyCode, type VerifyCodeName, addressToBytes, assertAggregationQuorum, attestationMessageHash, attestationMessageHashFromAttestation, base64ToBytes, bigIntFromBytesBe, bitmapBitSet, bitmapToIndices, buildEvmVerifierArgs, buildStarknetVerifierArgs, buildSubmitAttestationArgs, bytesToBase64, bytesToHex, bytesToHex0x, canonicalizeAPIConfig, canonicalizeAggregation, commitmentAddressToStarknetFelt, computeCoalitionKey, concatBytes, createEvmSignerFromPrivateKey, decodeInt256, deriveGatewayPda, deriveGatewayPdaAddress, deriveGroupBitmap, deriveSelectionBitmap, deriveSelectionSeed, deriveSourceId, deriveSourceIdString, domainSeparator, effectiveSelectionSize, eligibleSetSize, encodeEvmVerifyCalldata, encodeInt256, encodeInt256Decimal, encodeRequestAuth, encodeStarknetVerifyCalldata, ensureLength, estimateSubmitComputeUnits, evmAddressFromPrivateKey, feedPda, formatInt256Decimal, gatewayPda, getMolphaStarknetVerifierAddress, hashRequestAuth, hexToBytes, msUntilNextTick, nodePda, normalizeEndpoint, normalizeSecp256k1PublicKeyHex, parseEvmVerifyResult, parseGatewayInfo, parseStarknetVerifyResult, parseUpstreamQuote, planIdFromVariant, planPda, planVariant, probeSource, protocolConfigPda, registryPda, registryStatePda, requestMany, resolveRemainingAccounts, retryDelayMs, secp256k1PublicKeyFromCoordinates, selectedIndices, signSourcePayments, signersBitmapToDecimal, signersBitmapToStarknetUint256, signersBitmapToUint256, spreadOffsetMs, subscriptionPda, timestampAgeSeconds, timestampSeconds, toChecksumAddress, toFixedBytes, toFixedHex, transferWithAuthorizationDigest, transferWithAuthorizationHash, u256beFromBigInt, u32be, u32le, u64be, u64le, u8, utf8, validateSuppliedTerms, verifyCodeName };
|
|
1595
|
+
export { APIConfig, AdaptiveLimiter, AggregationConfig, AggregationConfigError, AssetDomain, Attestation, type AttestationMessageFields, type BuildEvmVerifierArgsOptions, type BuildStarknetVerifierArgsOptions, type BulkFeed, type BulkOptions, type BulkResult, type CoalitionKey, DEFAULT_GATEWAY_ENDPOINT, DEFAULT_MAX_RETRIES, DEFAULT_ROUND_TIMEOUT_MS, EIP712_DOMAIN_TYPEHASH, type Eip712Domain, type EvmAttestation, type EvmAttestationPayload, type EvmSchnorrSignature, EvmSigner, type EvmVerifierArgs, type EvmVerifyResult, type FeedAccount, type GatewayEndpoint, type GatewayEndpointInput, GatewayError, type GatewayInfo, INT256_MAX, INT256_MIN, MESSAGE_PREFIX, MIN_TOLERANCE_SIGNATURES, MOLPHA_DEV_VERIFIERS_PROVISIONAL, MOLPHA_IDL, MOLPHA_PROGRAM_ADDRESS, MOLPHA_PROGRAM_ID, MOLPHA_SDK_PROFILE, MOLPHA_VERIFIER_ABI, MOLPHA_VERIFIER_ADDRESS, MOLPHA_VERIFIER_STARKNET_ADDRESSES, MOLPHA_VERIFIER_STARKNET_SEPOLIA, type MolphaEvmNetwork, MolphaGateway, type MolphaGatewayOptions, MolphaSDK, type MolphaSDKOptions, MolphaSolanaClient, type MolphaStarknetNetwork, MolphaWallet, Node, NodeKeyVerifier, NodeKeyVerifierArgs, NodesInfo, type PlanId, type PlanInfo, PlanType, REQUEST_AUTH_DOMAIN, RegistrySelectionConfig, type RegistryStateView, type RegistryView, type RequestAuthFields, type RequestSignedDataOptions, type RetryCause, type RoundContext, SELECTION_WINDOW_MS, type Secp256k1KeyInput, Signer, SourcePaymentOptions, type StarknetAttestation, type StarknetAttestationPayload, type StarknetFeltLike, type StarknetSchnorrSignature, type StarknetVerifierArgs, type StarknetVerifyResult, type SubmitAttestationArgs, type SubmitAttestationOptions, SubmitFailedError, type SubmitResult, type SubscribeResult, type SubscriptionInfo, TRANSFER_WITH_AUTHORIZATION_TYPEHASH, type TransferAuthorization, UpstreamPaymentRequiredError, UpstreamQuote, UpstreamTerms, VERIFY_CODES, type VerifyCode, type VerifyCodeName, addressToBytes, assertAggregationQuorum, attestationMessageHash, attestationMessageHashFromAttestation, base64ToBytes, bigIntFromBytesBe, bitmapBitSet, bitmapToIndices, buildEvmVerifierArgs, buildStarknetVerifierArgs, buildSubmitAttestationArgs, bytesToBase64, bytesToHex, bytesToHex0x, canonicalizeAPIConfig, canonicalizeAggregation, commitmentAddressToStarknetFelt, computeCoalitionKey, concatBytes, createEvmSignerFromPrivateKey, decodeInt256, deriveGatewayPda, deriveGatewayPdaAddress, deriveGroupBitmap, deriveSelectionBitmap, deriveSelectionSeed, deriveSourceId, deriveSourceIdString, domainSeparator, effectiveSelectionSize, eligibleSetSize, encodeEvmVerifyCalldata, encodeInt256, encodeInt256Decimal, encodeRequestAuth, encodeStarknetVerifyCalldata, ensureLength, estimateSubmitComputeUnits, evmAddressFromPrivateKey, feedPda, formatInt256Decimal, gatewayPda, getMolphaStarknetVerifierAddress, hashRequestAuth, hexToBytes, msUntilNextTick, nodePda, normalizeEndpoint, normalizeSecp256k1PublicKeyHex, parseEvmVerifyResult, parseGatewayInfo, parseStarknetVerifyResult, parseUpstreamQuote, planIdFromVariant, planPda, planVariant, probeSource, protocolConfigPda, registryPda, registryStatePda, requestMany, resolveRemainingAccounts, retryDelayMs, secp256k1PublicKeyFromCoordinates, selectedIndices, signSourcePayments, signersBitmapToDecimal, signersBitmapToStarknetUint256, signersBitmapToUint256, spreadOffsetMs, subscriptionPda, timestampAgeSeconds, timestampSeconds, toChecksumAddress, toFixedBytes, toFixedHex, transferWithAuthorizationDigest, transferWithAuthorizationHash, u256beFromBigInt, u32be, u32le, u64be, u64le, u8, utf8, validateSuppliedTerms, verifyCodeName };
|
package/dist/index.js
CHANGED
|
@@ -201,8 +201,13 @@ function deriveSourceIdString(apiConfig) {
|
|
|
201
201
|
return bytesToHex(deriveSourceId(apiConfig));
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
-
// src/
|
|
204
|
+
// src/deployment.generated.ts
|
|
205
|
+
var MOLPHA_SDK_PROFILE = "dev";
|
|
206
|
+
var DEFAULT_GATEWAY_ENDPOINT = "https://dev-gateway.molpha.io/";
|
|
205
207
|
var MOLPHA_PROGRAM_ID = "chivcFQgxzwkpLvW41PV431HQ4dYpaW3povQH3AdpQt";
|
|
208
|
+
var MOLPHA_VERIFIER_ADDRESS = "0xE1fd792b7E54e0C8F0Cd1c8055E446ff36d233eB";
|
|
209
|
+
var MOLPHA_VERIFIER_STARKNET_SEPOLIA = "0x0378df4dbecf8f0c7daa801282932f7011c7a5e5773bab9eaf68f5fa5e7530ef";
|
|
210
|
+
var MOLPHA_DEV_VERIFIERS_PROVISIONAL = true;
|
|
206
211
|
|
|
207
212
|
// src/core/int256.ts
|
|
208
213
|
var INT256_MAX = (1n << 255n) - 1n;
|
|
@@ -581,6 +586,9 @@ var NETWORKS = {
|
|
|
581
586
|
base: { chainId: 8453, usdc: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" },
|
|
582
587
|
"base-sepolia": { chainId: 84532, usdc: "0x036CbD53842c5426634e7929541eC2318f3dCF7e" }
|
|
583
588
|
};
|
|
589
|
+
function newPaymentId() {
|
|
590
|
+
return `pay_${bytesToHex0x(randomBytes(16)).slice(2)}`;
|
|
591
|
+
}
|
|
584
592
|
var UpstreamPaymentRequiredError = class extends Error {
|
|
585
593
|
constructor(quote, message) {
|
|
586
594
|
super(
|
|
@@ -640,8 +648,11 @@ function selectTerms(envelope, resource, assetDomain) {
|
|
|
640
648
|
}
|
|
641
649
|
const payTo = String(supported.payTo ?? "");
|
|
642
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;
|
|
643
653
|
return {
|
|
644
654
|
x402Version: version,
|
|
655
|
+
paymentIdentifier,
|
|
645
656
|
// Echoed verbatim in the signed payload, so it must stay the source's own object.
|
|
646
657
|
requirements: supported,
|
|
647
658
|
network: String(supported.network),
|
|
@@ -737,6 +748,15 @@ async function signSourcePayments(terms, signer, count) {
|
|
|
737
748
|
accepted: terms.requirements,
|
|
738
749
|
payload: { signature, authorization }
|
|
739
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
|
+
}
|
|
740
760
|
payments.push(bytesToBase64(utf8(JSON.stringify(payload))));
|
|
741
761
|
}
|
|
742
762
|
return payments;
|
|
@@ -826,7 +846,6 @@ function retryAfterMs(res) {
|
|
|
826
846
|
const seconds = Number(raw);
|
|
827
847
|
return Number.isFinite(seconds) && seconds >= 0 ? Math.min(seconds, 60) * 1e3 : void 0;
|
|
828
848
|
}
|
|
829
|
-
var DEFAULT_GATEWAY_ENDPOINT = "https://dev-gateway.molpha.io/";
|
|
830
849
|
var GatewayError = class extends Error {
|
|
831
850
|
constructor(message, status) {
|
|
832
851
|
super(message);
|
|
@@ -10170,9 +10189,6 @@ var MOLPHA_VERIFIER_ABI = [
|
|
|
10170
10189
|
{ type: "error", name: "InvalidRegistryVersion", inputs: [] }
|
|
10171
10190
|
];
|
|
10172
10191
|
|
|
10173
|
-
// src/evm/constants.ts
|
|
10174
|
-
var MOLPHA_VERIFIER_ADDRESS = "0xE1fd792b7E54e0C8F0Cd1c8055E446ff36d233eB";
|
|
10175
|
-
|
|
10176
10192
|
// src/evm/helpers.ts
|
|
10177
10193
|
var VERIFY_SELECTOR = hexToBytes("67e2907b");
|
|
10178
10194
|
var U8_MAX = 0xffn;
|
|
@@ -10301,7 +10317,6 @@ function parseEvmVerifyResult(result) {
|
|
|
10301
10317
|
}
|
|
10302
10318
|
|
|
10303
10319
|
// src/starknet/constants.ts
|
|
10304
|
-
var MOLPHA_VERIFIER_STARKNET_SEPOLIA = "0x0378df4dbecf8f0c7daa801282932f7011c7a5e5773bab9eaf68f5fa5e7530ef";
|
|
10305
10320
|
var MOLPHA_VERIFIER_STARKNET_ADDRESSES = {
|
|
10306
10321
|
"starknet-sepolia": MOLPHA_VERIFIER_STARKNET_SEPOLIA
|
|
10307
10322
|
};
|
|
@@ -10607,6 +10622,6 @@ var MolphaSDK = class {
|
|
|
10607
10622
|
}
|
|
10608
10623
|
};
|
|
10609
10624
|
|
|
10610
|
-
export { AdaptiveLimiter, AggregationConfigError, DEFAULT_GATEWAY_ENDPOINT, DEFAULT_MAX_RETRIES, DEFAULT_ROUND_TIMEOUT_MS, EIP712_DOMAIN_TYPEHASH, GatewayError, INT256_MAX, INT256_MIN, MESSAGE_PREFIX, MIN_TOLERANCE_SIGNATURES, MOLPHA_IDL, MOLPHA_PROGRAM_ADDRESS, MOLPHA_PROGRAM_ID, MOLPHA_VERIFIER_ABI, MOLPHA_VERIFIER_ADDRESS, MOLPHA_VERIFIER_STARKNET_ADDRESSES, MOLPHA_VERIFIER_STARKNET_SEPOLIA, MolphaGateway, MolphaSDK, MolphaSolanaClient, PlanType, REQUEST_AUTH_DOMAIN, SELECTION_WINDOW_MS, SubmitFailedError, TRANSFER_WITH_AUTHORIZATION_TYPEHASH, UpstreamPaymentRequiredError, VERIFY_CODES, addressToBytes, assertAggregationQuorum, attestationMessageHash, attestationMessageHashFromAttestation, base64ToBytes, bigIntFromBytesBe, bitmapBitSet, bitmapToIndices, buildEvmVerifierArgs, buildStarknetVerifierArgs, buildSubmitAttestationArgs, bytesToBase64, bytesToHex, bytesToHex0x, canonicalizeAPIConfig, canonicalizeAggregation, commitmentAddressToStarknetFelt, computeCoalitionKey, concatBytes, createEvmSignerFromPrivateKey, decodeInt256, deriveGatewayPda, deriveGatewayPdaAddress, deriveGroupBitmap, deriveSelectionBitmap, deriveSelectionSeed, deriveSourceId, deriveSourceIdString, domainSeparator, effectiveSelectionSize, eligibleSetSize, encodeEvmVerifyCalldata, encodeInt256, encodeInt256Decimal, encodeRequestAuth, encodeStarknetVerifyCalldata, ensureLength, estimateSubmitComputeUnits, evmAddressFromPrivateKey, feedPda, formatInt256Decimal, gatewayPda, gatewaySignerFromWallet, getMolphaStarknetVerifierAddress, hashRequestAuth, hexToBytes, msUntilNextTick, nodePda, normalizeEndpoint, normalizeSecp256k1PublicKeyHex, parseEvmVerifyResult, parseGatewayInfo, parseStarknetVerifyResult, parseUpstreamQuote, planIdFromVariant, planPda, planVariant, probeSource, protocolConfigPda, registryPda, registryStatePda, requestMany, resolveRemainingAccounts, retryDelayMs, secp256k1PublicKeyFromCoordinates, selectedIndices, signSourcePayments, signerFromKeypair, signersBitmapToDecimal, signersBitmapToStarknetUint256, signersBitmapToUint256, spreadOffsetMs, subscriptionPda, timestampAgeSeconds, timestampSeconds, toChecksumAddress, toFixedBytes, toFixedHex, transferWithAuthorizationDigest, transferWithAuthorizationHash, u256beFromBigInt, u32be, u32le, u64be, u64le, u8, utf8, validateSuppliedTerms, verifyCodeName };
|
|
10625
|
+
export { AdaptiveLimiter, AggregationConfigError, DEFAULT_GATEWAY_ENDPOINT, DEFAULT_MAX_RETRIES, DEFAULT_ROUND_TIMEOUT_MS, EIP712_DOMAIN_TYPEHASH, GatewayError, INT256_MAX, INT256_MIN, MESSAGE_PREFIX, MIN_TOLERANCE_SIGNATURES, MOLPHA_DEV_VERIFIERS_PROVISIONAL, MOLPHA_IDL, MOLPHA_PROGRAM_ADDRESS, MOLPHA_PROGRAM_ID, MOLPHA_SDK_PROFILE, MOLPHA_VERIFIER_ABI, MOLPHA_VERIFIER_ADDRESS, MOLPHA_VERIFIER_STARKNET_ADDRESSES, MOLPHA_VERIFIER_STARKNET_SEPOLIA, MolphaGateway, MolphaSDK, MolphaSolanaClient, PlanType, REQUEST_AUTH_DOMAIN, SELECTION_WINDOW_MS, SubmitFailedError, TRANSFER_WITH_AUTHORIZATION_TYPEHASH, UpstreamPaymentRequiredError, VERIFY_CODES, addressToBytes, assertAggregationQuorum, attestationMessageHash, attestationMessageHashFromAttestation, base64ToBytes, bigIntFromBytesBe, bitmapBitSet, bitmapToIndices, buildEvmVerifierArgs, buildStarknetVerifierArgs, buildSubmitAttestationArgs, bytesToBase64, bytesToHex, bytesToHex0x, canonicalizeAPIConfig, canonicalizeAggregation, commitmentAddressToStarknetFelt, computeCoalitionKey, concatBytes, createEvmSignerFromPrivateKey, decodeInt256, deriveGatewayPda, deriveGatewayPdaAddress, deriveGroupBitmap, deriveSelectionBitmap, deriveSelectionSeed, deriveSourceId, deriveSourceIdString, domainSeparator, effectiveSelectionSize, eligibleSetSize, encodeEvmVerifyCalldata, encodeInt256, encodeInt256Decimal, encodeRequestAuth, encodeStarknetVerifyCalldata, ensureLength, estimateSubmitComputeUnits, evmAddressFromPrivateKey, feedPda, formatInt256Decimal, gatewayPda, gatewaySignerFromWallet, getMolphaStarknetVerifierAddress, hashRequestAuth, hexToBytes, msUntilNextTick, nodePda, normalizeEndpoint, normalizeSecp256k1PublicKeyHex, parseEvmVerifyResult, parseGatewayInfo, parseStarknetVerifyResult, parseUpstreamQuote, planIdFromVariant, planPda, planVariant, probeSource, protocolConfigPda, registryPda, registryStatePda, requestMany, resolveRemainingAccounts, retryDelayMs, secp256k1PublicKeyFromCoordinates, selectedIndices, signSourcePayments, signerFromKeypair, signersBitmapToDecimal, signersBitmapToStarknetUint256, signersBitmapToUint256, spreadOffsetMs, subscriptionPda, timestampAgeSeconds, timestampSeconds, toChecksumAddress, toFixedBytes, toFixedHex, transferWithAuthorizationDigest, transferWithAuthorizationHash, u256beFromBigInt, u32be, u32le, u64be, u64le, u8, utf8, validateSuppliedTerms, verifyCodeName };
|
|
10611
10626
|
//# sourceMappingURL=index.js.map
|
|
10612
10627
|
//# sourceMappingURL=index.js.map
|