@chipi-stack/backend 14.15.0 → 14.16.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/dist/index.d.mts CHANGED
@@ -8,7 +8,7 @@ import { ChipiTransactions } from './transactions.mjs';
8
8
  import { ChipiSkuPurchases } from './skuPurchases.mjs';
9
9
  import { ChipiSkus } from './skus.mjs';
10
10
  import { C as ChipiClient } from './client-D6SDBu5p.mjs';
11
- import { Call, ProviderInterface, Account } from 'starknet';
11
+ import { Call, TypedData, ProviderInterface, Account } from 'starknet';
12
12
 
13
13
  /**
14
14
  * Session key management for CHIPI wallets (SNIP-9 compatible).
@@ -649,9 +649,13 @@ declare class ChipiAi {
649
649
  * session key: a USDC `transfer` to the offer's `payTo`, then the same call
650
650
  * again with `X-PAYMENT`. The price must be at most `maxAmount`, `model`
651
651
  * must be payable and the input within `maxPromptBytes`, all checked before
652
- * paying. The session must whitelist `transfer` and cap USDC. A payment
653
- * that was made but not served is reported in `error.details.xPayment`;
654
- * pass it back as `options.xPayment` to retry without paying again.
652
+ * paying. The wallet must be a wallet of the organization that owns the
653
+ * `sk_`: the first request names it in `X-PAYER`, and when the API answers
654
+ * that a payment from it would be refused, nothing is paid
655
+ * (`X402_PAYER_NOT_IN_ORG`). The session must whitelist `transfer` and cap
656
+ * USDC. A payment that was made but not served is reported in
657
+ * `error.details.xPayment`; pass it back as `options.xPayment` to retry
658
+ * without paying again.
655
659
  *
656
660
  * @example
657
661
  * ```typescript
@@ -751,11 +755,18 @@ declare class X402Facilitator {
751
755
  * Verify a payment signature is valid (doesn't execute the transfer).
752
756
  *
753
757
  * Checks:
754
- * 1. Nonce has not been used (replay protection)
755
- * 2. Payment has not expired (validUntil > now)
756
- * 3. Asset is USDC mainnet
757
- * 4. Amount is positive
758
- * 5. Addresses are non-empty
758
+ * 1. x402 version is 1
759
+ * 2. Network is starknet-mainnet
760
+ * 3. Nonce has not been used (replay protection)
761
+ * 4. Payment has not expired (validUntil > now)
762
+ * 5. Asset is USDC mainnet
763
+ * 6. Amount is positive
764
+ * 7. Addresses are non-empty
765
+ * 8. Signature: with a `provider`, the payer account's `is_valid_signature`
766
+ * must return 'VALID'. Without one, only its presence is checked (not a
767
+ * cryptographic check). SHHH payloads must sign exactly one transfer
768
+ * of `amount` of `asset` to `toAddress`; their signature is checked
769
+ * on-chain at settle.
759
770
  */
760
771
  verify(payment: PaymentPayload): Promise<VerifyResponse>;
761
772
  /**
@@ -1468,6 +1479,148 @@ declare class SessionTxVerifier {
1468
1479
  verifyTransfer(params: VerifyTransferParams): Promise<VerifyTransferResult>;
1469
1480
  }
1470
1481
 
1482
+ /** SRC-6 `is_valid_signature` magic value: the short string 'VALID'. */
1483
+ declare const STARKNET_SIGNATURE_VALID = "0x56414c4944";
1484
+ /** Anything with a starknet.js-style `callContract` (e.g. `RpcProvider`). */
1485
+ interface StarknetCallProvider {
1486
+ callContract(call: {
1487
+ contractAddress: string;
1488
+ entrypoint: string;
1489
+ calldata?: string[];
1490
+ }): Promise<string[]>;
1491
+ }
1492
+ type StarknetSignatureCheck = {
1493
+ valid: true;
1494
+ } | {
1495
+ valid: false;
1496
+ reason: "INVALID_SIGNATURE" | "ACCOUNT_NOT_DEPLOYED";
1497
+ detail?: string;
1498
+ };
1499
+ /** `0x` + 64 hex, lowercase. Wallets differ on padding; compare on this. */
1500
+ declare function normalizeStarknetAddress(address: string): string;
1501
+ /**
1502
+ * Asks the account itself (SRC-6 `is_valid_signature`) whether `signature`
1503
+ * signs `messageHash`. The full signature array is passed through, so
1504
+ * multi-felt signatures (Argent, Braavos, multisig) work.
1505
+ *
1506
+ * Only 'VALID' counts: accounts return 0 or panic on a bad signature, and a
1507
+ * lax "anything non-zero" check would accept garbage. An account that is not
1508
+ * deployed yet comes back as ACCOUNT_NOT_DEPLOYED so the caller can fall back
1509
+ * to `verifyUndeployedStarknetSignature`.
1510
+ */
1511
+ declare function isValidStarknetSignature(provider: StarknetCallProvider, accountAddress: string, messageHash: string, signature: Array<string | number | bigint>): Promise<StarknetSignatureCheck>;
1512
+ /** Account classes whose undeployed signatures we can check off-chain. */
1513
+ declare const COUNTERFACTUAL_ACCOUNT_CLASSES: {
1514
+ /** OpenZeppelin AccountUpgradeable 3.0 (Bramble's default account). */
1515
+ readonly OPENZEPPELIN_V3: "0x01d1777db36cdd06dd62cfde77b1b6ae06412af95d57a13dc40ac77b8a702381";
1516
+ /** Argent X / Ready 0.4 (`WALLET_CLASS_HASHES.READY`). */
1517
+ readonly ARGENT_V0_4: "0x036078334509b514626504edc9fb252328d1a240e4e948bef8d0c08dff45927f";
1518
+ };
1519
+ /** What a wallet returns from `wallet_deploymentData`. */
1520
+ interface StarknetDeploymentData {
1521
+ address: string;
1522
+ class_hash: string;
1523
+ salt: string;
1524
+ calldata: string[];
1525
+ }
1526
+ type UndeployedSignatureCheck = {
1527
+ valid: true;
1528
+ } | {
1529
+ valid: false;
1530
+ reason: "UNSUPPORTED_ACCOUNT_CLASS" | "ADDRESS_MISMATCH" | "INVALID_SIGNATURE";
1531
+ };
1532
+ /**
1533
+ * Checks a signature from an account that is not deployed yet (new Bramble
1534
+ * and Ready accounts stay counterfactual until their first transaction), using
1535
+ * the wallet's `wallet_deploymentData`:
1536
+ *
1537
+ * 1. The class must be one we know how to read: OpenZeppelin 3.0 or Argent 0.4
1538
+ * without a guardian.
1539
+ * 2. The address must be the one those exact constructor arguments deploy to.
1540
+ * 3. The signature must be the owner key's ECDSA signature of the hash.
1541
+ */
1542
+ declare function verifyUndeployedStarknetSignature(deployment: StarknetDeploymentData, messageHash: string, signature: Array<string | number | bigint>): UndeployedSignatureCheck;
1543
+
1544
+ /**
1545
+ * Sign in with Starknet (SIWS): the SNIP-12 equivalent of Sign-In with
1546
+ * Ethereum. The server issues a one-time nonce, the wallet signs this typed
1547
+ * data, and the server checks the signature with the account itself.
1548
+ *
1549
+ * The typed data is kept to what every wallet accepts: SNIP-12 revision 1,
1550
+ * mainnet chain id in the domain, single-line printable ASCII strings (Bramble
1551
+ * refuses anything else), and no custom `u256`.
1552
+ */
1553
+ declare const SIWS_DOMAIN_NAME = "Sign in with Starknet";
1554
+ declare const SIWS_DOMAIN_VERSION = "1";
1555
+ declare const SIWS_CHAIN_ID = "SN_MAIN";
1556
+ interface StarknetSignInParams {
1557
+ /** Host asking for the sign-in, e.g. "vela-starknet.vercel.app". */
1558
+ domain: string;
1559
+ /** Full URL of the app, e.g. "https://vela-starknet.vercel.app". */
1560
+ uri: string;
1561
+ /** Account that signs. Any padding; stored as 0x + 64 hex. */
1562
+ address: string;
1563
+ /** One-time server nonce (letters and digits). */
1564
+ nonce: string;
1565
+ /** Shown to the user in the wallet. */
1566
+ statement?: string;
1567
+ /** Unix seconds. Defaults to now. */
1568
+ issuedAt?: number;
1569
+ /** Unix seconds. */
1570
+ expirationTime: number;
1571
+ }
1572
+ interface StarknetSignInMessage {
1573
+ domain: string;
1574
+ address: string;
1575
+ statement: string;
1576
+ uri: string;
1577
+ nonce: string;
1578
+ issuedAt: number;
1579
+ expirationTime: number;
1580
+ }
1581
+ /** Typed data for the wallet's `wallet_signTypedData`. */
1582
+ declare function createStarknetSignInTypedData(params: StarknetSignInParams): TypedData;
1583
+ interface VerifyStarknetSignInParams {
1584
+ /** The typed data the wallet signed, as returned to the client. */
1585
+ typedData: TypedData;
1586
+ /** The wallet's `wallet_signTypedData` result (hex or decimal felts). */
1587
+ signature: Array<string | number | bigint>;
1588
+ /** Mainnet RPC (starknet.js `RpcProvider` or anything with `callContract`). */
1589
+ provider: StarknetCallProvider;
1590
+ /** What this server issued. Anything else is refused. */
1591
+ expected: {
1592
+ domain: string;
1593
+ uri: string;
1594
+ nonce: string;
1595
+ now?: number;
1596
+ };
1597
+ /**
1598
+ * The wallet's `wallet_deploymentData`, for accounts not deployed yet
1599
+ * (new Bramble/Ready accounts). Only used when the RPC says the account
1600
+ * does not exist.
1601
+ */
1602
+ deploymentData?: StarknetDeploymentData;
1603
+ }
1604
+ type StarknetSignInFailure = "MALFORMED" | "WRONG_CHAIN" | "WRONG_DOMAIN" | "WRONG_URI" | "WRONG_NONCE" | "EXPIRED" | "NOT_YET_VALID" | "INVALID_SIGNATURE" | "ACCOUNT_NOT_DEPLOYED" | "UNSUPPORTED_ACCOUNT_CLASS" | "ADDRESS_MISMATCH";
1605
+ type VerifyStarknetSignInResult = {
1606
+ ok: true;
1607
+ address: string;
1608
+ message: StarknetSignInMessage;
1609
+ } | {
1610
+ ok: false;
1611
+ reason: StarknetSignInFailure;
1612
+ };
1613
+ /**
1614
+ * Verifies a SIWS signature. The typed data is rebuilt from its message with
1615
+ * `createStarknetSignInTypedData`, so a client can't swap in other types or a
1616
+ * testnet domain; then the account is asked with `is_valid_signature`, or, if
1617
+ * it isn't deployed yet and `deploymentData` is given, checked off-chain.
1618
+ *
1619
+ * The caller still owns the nonce: issue it once, and consume it before or
1620
+ * right after calling this (never accept the same nonce twice).
1621
+ */
1622
+ declare function verifyStarknetSignIn(params: VerifyStarknetSignInParams): Promise<VerifyStarknetSignInResult>;
1623
+
1471
1624
  /**
1472
1625
  * SNIP-12 typed-data hash for `OutsideExecution` — TypeScript reference.
1473
1626
  *
@@ -3045,4 +3198,4 @@ declare class ShhhAccount {
3045
3198
  */
3046
3199
  declare function submitViaAccount(funded: Account): ShhhSubmit;
3047
3200
 
3048
- export { ANY_CALLER_FELT, APPLE_ISSUER, type AppleTokenResponse, type ApproveBody, BOOTSTRAP_DOMAIN_SEPARATOR, type BootstrapMessageParams, type BuildBootstrapSignedCallParams, type BuildMigrationCallsParams, ChipiAi, ChipiBrowserSDK, ChipiClient, ChipiPaymasterAdapter, ChipiSDK, ChipiServerSDK, ChipiSessions, ChipiSkuPurchases, ChipiSkus, ChipiTransactions, ChipiTreasury, ChipiWallets, type ComputeAddressInput, type ContractEventLog, DEFAULT_OP_EXPIRY_SECONDS, type Eip191Pubkey, type ExecuteResult, type ForTreasuryConfig, ISIGNER_CANONICAL_LABEL, ISIGNER_ID, ISRC9_V2_ID, type JwtAppleSubPubkey, type ListTreasuriesOptions, type ListTreasuriesResult, MAX_OE_VALIDITY_WINDOW_SECONDS, MIN_THRESHOLD_OWNERS, type MultisigAllowance, type NewOwnerInput, OE_DOMAIN_NAME, OE_DOMAIN_REVISION, OE_DOMAIN_VERSION, OP_ADD_OWNER, OP_REMOVE_OWNER, OP_ROTATE_OWNER, OP_SET_THRESHOLD, type OutsideExecution, type OwnerRole, type ProposeBody, ROLE_GUARDIAN, ROLE_OWNER, SIG_VERSION_V1_HEX_ASCII, SIG_VERSION_V2_SNIP12, SIG_VERSION_V2_THRESHOLD, STARKNET_MESSAGE_PREFIX, SessionTxVerifier, type SessionTxVerifierConfig, type SetTreasuryPolicyOptions, ShhhAccount, type ShhhAccountOptions, type ShhhExecuteOptions, type ShhhSignedExecution, type ShhhSubmit, type ShhhX402Wallet, TIMELOCK_SECONDS, type TreasuryPolicy, type TreasuryProposal, type TreasuryProposalSignature, type TreasurySummary, type TreasuryTransport, type TxHashStore, VIEW_SELECTORS, type VerifyTransferFailure, type VerifyTransferParams, type VerifyTransferResult, type WaitForTransactionOptions, type WaitForTransactionResult, type WebAuthnPubkey, X402Facilitator, type X402FacilitatorCreateOptions, type X402MiddlewareConfig, type X402MiddlewareFlatConfig, X402ShhhClient, type X402ShhhClientConfig, assertValidV2Snip12Envelope, buildAddSessionKeyCall, buildBootstrapSignedCall, buildCancelPendingOpCall, buildCancelRecoveryCall, buildEd25519Envelope, buildEd25519EnvelopeFromSignature, buildEip191EnvelopeFromPrivateKey, buildEip191EnvelopeFromSignature, buildExecuteAddOwnerCall, buildExecuteRemoveOwnerCall, buildExecuteRotateOwnerCall, buildExecuteSetThresholdCall, buildFinalizeRecoveryCall, buildInitiateRecoveryCall, buildJwtAppleSubEnvelopeFromTestKey, buildJwtAppleSubEnvelopeFromTokenResponse, buildMigrationCalls, buildOutsideExecution, buildProposeAddOwnerCall, buildProposeRemoveOwnerCall, buildProposeRotateOwnerCall, buildProposeSetThresholdCall, buildRemoveSpendingPolicyCall, buildRevokeSessionKeyCall, buildSessionSetupCalls, buildSetSpendingPolicyCall, buildStarkEnvelope, buildThresholdEnvelope, buildWebAuthnEnvelopeFromAssertion, buildWebAuthnEnvelopeFromPrivateKey, byteArrayToFelts, computeAddressSalt, computeBootstrapMessage, computeISignerId, computeOeHash, computeShhhAddress, computeSnip12Hash, decryptPrivateKey, ed25519OwnerId, ed25519OwnerPubkeyParam, ed25519PubkeyFelts, ed25519SignedBytes, eip191OwnerId, eip191OwnerPubkeyParam, eip191PubkeyFelts, encryptPrivateKey, estimateThresholdGasOverhead, executeShhhSponsoredRaw, hashCall, hashCalls, hashOutsideExecutionStruct, hashStarknetDomain, isReadyToExecute, isThinkDecision, jwtAppleSubHash, jwtAppleSubOwnerId, jwtAppleSubPubkeyFelts, labelToFelt, locateSubClaim, messageHashToNonceB64url, normalizeEntrypoints, ownerCommitment, parseAppleIdToken, parseDerEcdsaSignature, parseEip191Signature, parseThresholdEnvelope, resolveShhhChainId, secondsUntilExecutable, serializeExecuteFromOutsideV2Calldata, signBootstrapMessage, signTypedData, signTypedDataArray, snip12HashToHexAsciiBytes, starkOwnerId, starkPubkeyFelts, submitViaAccount, validateSpendingPolicyConfig, waitForTransaction, webauthnOwnerId, webauthnOwnerPubkeyParam, webauthnPubkeyFelts, wrapV2Snip12Envelope, wrapV2ThresholdEnvelope, x402Middleware };
3201
+ export { ANY_CALLER_FELT, APPLE_ISSUER, type AppleTokenResponse, type ApproveBody, BOOTSTRAP_DOMAIN_SEPARATOR, type BootstrapMessageParams, type BuildBootstrapSignedCallParams, type BuildMigrationCallsParams, COUNTERFACTUAL_ACCOUNT_CLASSES, ChipiAi, ChipiBrowserSDK, ChipiClient, ChipiPaymasterAdapter, ChipiSDK, ChipiServerSDK, ChipiSessions, ChipiSkuPurchases, ChipiSkus, ChipiTransactions, ChipiTreasury, ChipiWallets, type ComputeAddressInput, type ContractEventLog, DEFAULT_OP_EXPIRY_SECONDS, type Eip191Pubkey, type ExecuteResult, type ForTreasuryConfig, ISIGNER_CANONICAL_LABEL, ISIGNER_ID, ISRC9_V2_ID, type JwtAppleSubPubkey, type ListTreasuriesOptions, type ListTreasuriesResult, MAX_OE_VALIDITY_WINDOW_SECONDS, MIN_THRESHOLD_OWNERS, type MultisigAllowance, type NewOwnerInput, OE_DOMAIN_NAME, OE_DOMAIN_REVISION, OE_DOMAIN_VERSION, OP_ADD_OWNER, OP_REMOVE_OWNER, OP_ROTATE_OWNER, OP_SET_THRESHOLD, type OutsideExecution, type OwnerRole, type ProposeBody, ROLE_GUARDIAN, ROLE_OWNER, SIG_VERSION_V1_HEX_ASCII, SIG_VERSION_V2_SNIP12, SIG_VERSION_V2_THRESHOLD, SIWS_CHAIN_ID, SIWS_DOMAIN_NAME, SIWS_DOMAIN_VERSION, STARKNET_MESSAGE_PREFIX, STARKNET_SIGNATURE_VALID, SessionTxVerifier, type SessionTxVerifierConfig, type SetTreasuryPolicyOptions, ShhhAccount, type ShhhAccountOptions, type ShhhExecuteOptions, type ShhhSignedExecution, type ShhhSubmit, type ShhhX402Wallet, type StarknetCallProvider, type StarknetDeploymentData, type StarknetSignInFailure, type StarknetSignInMessage, type StarknetSignInParams, type StarknetSignatureCheck, TIMELOCK_SECONDS, type TreasuryPolicy, type TreasuryProposal, type TreasuryProposalSignature, type TreasurySummary, type TreasuryTransport, type TxHashStore, type UndeployedSignatureCheck, VIEW_SELECTORS, type VerifyStarknetSignInParams, type VerifyStarknetSignInResult, type VerifyTransferFailure, type VerifyTransferParams, type VerifyTransferResult, type WaitForTransactionOptions, type WaitForTransactionResult, type WebAuthnPubkey, X402Facilitator, type X402FacilitatorCreateOptions, type X402MiddlewareConfig, type X402MiddlewareFlatConfig, X402ShhhClient, type X402ShhhClientConfig, assertValidV2Snip12Envelope, buildAddSessionKeyCall, buildBootstrapSignedCall, buildCancelPendingOpCall, buildCancelRecoveryCall, buildEd25519Envelope, buildEd25519EnvelopeFromSignature, buildEip191EnvelopeFromPrivateKey, buildEip191EnvelopeFromSignature, buildExecuteAddOwnerCall, buildExecuteRemoveOwnerCall, buildExecuteRotateOwnerCall, buildExecuteSetThresholdCall, buildFinalizeRecoveryCall, buildInitiateRecoveryCall, buildJwtAppleSubEnvelopeFromTestKey, buildJwtAppleSubEnvelopeFromTokenResponse, buildMigrationCalls, buildOutsideExecution, buildProposeAddOwnerCall, buildProposeRemoveOwnerCall, buildProposeRotateOwnerCall, buildProposeSetThresholdCall, buildRemoveSpendingPolicyCall, buildRevokeSessionKeyCall, buildSessionSetupCalls, buildSetSpendingPolicyCall, buildStarkEnvelope, buildThresholdEnvelope, buildWebAuthnEnvelopeFromAssertion, buildWebAuthnEnvelopeFromPrivateKey, byteArrayToFelts, computeAddressSalt, computeBootstrapMessage, computeISignerId, computeOeHash, computeShhhAddress, computeSnip12Hash, createStarknetSignInTypedData, decryptPrivateKey, ed25519OwnerId, ed25519OwnerPubkeyParam, ed25519PubkeyFelts, ed25519SignedBytes, eip191OwnerId, eip191OwnerPubkeyParam, eip191PubkeyFelts, encryptPrivateKey, estimateThresholdGasOverhead, executeShhhSponsoredRaw, hashCall, hashCalls, hashOutsideExecutionStruct, hashStarknetDomain, isReadyToExecute, isThinkDecision, isValidStarknetSignature, jwtAppleSubHash, jwtAppleSubOwnerId, jwtAppleSubPubkeyFelts, labelToFelt, locateSubClaim, messageHashToNonceB64url, normalizeEntrypoints, normalizeStarknetAddress, ownerCommitment, parseAppleIdToken, parseDerEcdsaSignature, parseEip191Signature, parseThresholdEnvelope, resolveShhhChainId, secondsUntilExecutable, serializeExecuteFromOutsideV2Calldata, signBootstrapMessage, signTypedData, signTypedDataArray, snip12HashToHexAsciiBytes, starkOwnerId, starkPubkeyFelts, submitViaAccount, validateSpendingPolicyConfig, verifyStarknetSignIn, verifyUndeployedStarknetSignature, waitForTransaction, webauthnOwnerId, webauthnOwnerPubkeyParam, webauthnPubkeyFelts, wrapV2Snip12Envelope, wrapV2ThresholdEnvelope, x402Middleware };
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ import { ChipiTransactions } from './transactions.js';
8
8
  import { ChipiSkuPurchases } from './skuPurchases.js';
9
9
  import { ChipiSkus } from './skus.js';
10
10
  import { C as ChipiClient } from './client-D6SDBu5p.js';
11
- import { Call, ProviderInterface, Account } from 'starknet';
11
+ import { Call, TypedData, ProviderInterface, Account } from 'starknet';
12
12
 
13
13
  /**
14
14
  * Session key management for CHIPI wallets (SNIP-9 compatible).
@@ -649,9 +649,13 @@ declare class ChipiAi {
649
649
  * session key: a USDC `transfer` to the offer's `payTo`, then the same call
650
650
  * again with `X-PAYMENT`. The price must be at most `maxAmount`, `model`
651
651
  * must be payable and the input within `maxPromptBytes`, all checked before
652
- * paying. The session must whitelist `transfer` and cap USDC. A payment
653
- * that was made but not served is reported in `error.details.xPayment`;
654
- * pass it back as `options.xPayment` to retry without paying again.
652
+ * paying. The wallet must be a wallet of the organization that owns the
653
+ * `sk_`: the first request names it in `X-PAYER`, and when the API answers
654
+ * that a payment from it would be refused, nothing is paid
655
+ * (`X402_PAYER_NOT_IN_ORG`). The session must whitelist `transfer` and cap
656
+ * USDC. A payment that was made but not served is reported in
657
+ * `error.details.xPayment`; pass it back as `options.xPayment` to retry
658
+ * without paying again.
655
659
  *
656
660
  * @example
657
661
  * ```typescript
@@ -751,11 +755,18 @@ declare class X402Facilitator {
751
755
  * Verify a payment signature is valid (doesn't execute the transfer).
752
756
  *
753
757
  * Checks:
754
- * 1. Nonce has not been used (replay protection)
755
- * 2. Payment has not expired (validUntil > now)
756
- * 3. Asset is USDC mainnet
757
- * 4. Amount is positive
758
- * 5. Addresses are non-empty
758
+ * 1. x402 version is 1
759
+ * 2. Network is starknet-mainnet
760
+ * 3. Nonce has not been used (replay protection)
761
+ * 4. Payment has not expired (validUntil > now)
762
+ * 5. Asset is USDC mainnet
763
+ * 6. Amount is positive
764
+ * 7. Addresses are non-empty
765
+ * 8. Signature: with a `provider`, the payer account's `is_valid_signature`
766
+ * must return 'VALID'. Without one, only its presence is checked (not a
767
+ * cryptographic check). SHHH payloads must sign exactly one transfer
768
+ * of `amount` of `asset` to `toAddress`; their signature is checked
769
+ * on-chain at settle.
759
770
  */
760
771
  verify(payment: PaymentPayload): Promise<VerifyResponse>;
761
772
  /**
@@ -1468,6 +1479,148 @@ declare class SessionTxVerifier {
1468
1479
  verifyTransfer(params: VerifyTransferParams): Promise<VerifyTransferResult>;
1469
1480
  }
1470
1481
 
1482
+ /** SRC-6 `is_valid_signature` magic value: the short string 'VALID'. */
1483
+ declare const STARKNET_SIGNATURE_VALID = "0x56414c4944";
1484
+ /** Anything with a starknet.js-style `callContract` (e.g. `RpcProvider`). */
1485
+ interface StarknetCallProvider {
1486
+ callContract(call: {
1487
+ contractAddress: string;
1488
+ entrypoint: string;
1489
+ calldata?: string[];
1490
+ }): Promise<string[]>;
1491
+ }
1492
+ type StarknetSignatureCheck = {
1493
+ valid: true;
1494
+ } | {
1495
+ valid: false;
1496
+ reason: "INVALID_SIGNATURE" | "ACCOUNT_NOT_DEPLOYED";
1497
+ detail?: string;
1498
+ };
1499
+ /** `0x` + 64 hex, lowercase. Wallets differ on padding; compare on this. */
1500
+ declare function normalizeStarknetAddress(address: string): string;
1501
+ /**
1502
+ * Asks the account itself (SRC-6 `is_valid_signature`) whether `signature`
1503
+ * signs `messageHash`. The full signature array is passed through, so
1504
+ * multi-felt signatures (Argent, Braavos, multisig) work.
1505
+ *
1506
+ * Only 'VALID' counts: accounts return 0 or panic on a bad signature, and a
1507
+ * lax "anything non-zero" check would accept garbage. An account that is not
1508
+ * deployed yet comes back as ACCOUNT_NOT_DEPLOYED so the caller can fall back
1509
+ * to `verifyUndeployedStarknetSignature`.
1510
+ */
1511
+ declare function isValidStarknetSignature(provider: StarknetCallProvider, accountAddress: string, messageHash: string, signature: Array<string | number | bigint>): Promise<StarknetSignatureCheck>;
1512
+ /** Account classes whose undeployed signatures we can check off-chain. */
1513
+ declare const COUNTERFACTUAL_ACCOUNT_CLASSES: {
1514
+ /** OpenZeppelin AccountUpgradeable 3.0 (Bramble's default account). */
1515
+ readonly OPENZEPPELIN_V3: "0x01d1777db36cdd06dd62cfde77b1b6ae06412af95d57a13dc40ac77b8a702381";
1516
+ /** Argent X / Ready 0.4 (`WALLET_CLASS_HASHES.READY`). */
1517
+ readonly ARGENT_V0_4: "0x036078334509b514626504edc9fb252328d1a240e4e948bef8d0c08dff45927f";
1518
+ };
1519
+ /** What a wallet returns from `wallet_deploymentData`. */
1520
+ interface StarknetDeploymentData {
1521
+ address: string;
1522
+ class_hash: string;
1523
+ salt: string;
1524
+ calldata: string[];
1525
+ }
1526
+ type UndeployedSignatureCheck = {
1527
+ valid: true;
1528
+ } | {
1529
+ valid: false;
1530
+ reason: "UNSUPPORTED_ACCOUNT_CLASS" | "ADDRESS_MISMATCH" | "INVALID_SIGNATURE";
1531
+ };
1532
+ /**
1533
+ * Checks a signature from an account that is not deployed yet (new Bramble
1534
+ * and Ready accounts stay counterfactual until their first transaction), using
1535
+ * the wallet's `wallet_deploymentData`:
1536
+ *
1537
+ * 1. The class must be one we know how to read: OpenZeppelin 3.0 or Argent 0.4
1538
+ * without a guardian.
1539
+ * 2. The address must be the one those exact constructor arguments deploy to.
1540
+ * 3. The signature must be the owner key's ECDSA signature of the hash.
1541
+ */
1542
+ declare function verifyUndeployedStarknetSignature(deployment: StarknetDeploymentData, messageHash: string, signature: Array<string | number | bigint>): UndeployedSignatureCheck;
1543
+
1544
+ /**
1545
+ * Sign in with Starknet (SIWS): the SNIP-12 equivalent of Sign-In with
1546
+ * Ethereum. The server issues a one-time nonce, the wallet signs this typed
1547
+ * data, and the server checks the signature with the account itself.
1548
+ *
1549
+ * The typed data is kept to what every wallet accepts: SNIP-12 revision 1,
1550
+ * mainnet chain id in the domain, single-line printable ASCII strings (Bramble
1551
+ * refuses anything else), and no custom `u256`.
1552
+ */
1553
+ declare const SIWS_DOMAIN_NAME = "Sign in with Starknet";
1554
+ declare const SIWS_DOMAIN_VERSION = "1";
1555
+ declare const SIWS_CHAIN_ID = "SN_MAIN";
1556
+ interface StarknetSignInParams {
1557
+ /** Host asking for the sign-in, e.g. "vela-starknet.vercel.app". */
1558
+ domain: string;
1559
+ /** Full URL of the app, e.g. "https://vela-starknet.vercel.app". */
1560
+ uri: string;
1561
+ /** Account that signs. Any padding; stored as 0x + 64 hex. */
1562
+ address: string;
1563
+ /** One-time server nonce (letters and digits). */
1564
+ nonce: string;
1565
+ /** Shown to the user in the wallet. */
1566
+ statement?: string;
1567
+ /** Unix seconds. Defaults to now. */
1568
+ issuedAt?: number;
1569
+ /** Unix seconds. */
1570
+ expirationTime: number;
1571
+ }
1572
+ interface StarknetSignInMessage {
1573
+ domain: string;
1574
+ address: string;
1575
+ statement: string;
1576
+ uri: string;
1577
+ nonce: string;
1578
+ issuedAt: number;
1579
+ expirationTime: number;
1580
+ }
1581
+ /** Typed data for the wallet's `wallet_signTypedData`. */
1582
+ declare function createStarknetSignInTypedData(params: StarknetSignInParams): TypedData;
1583
+ interface VerifyStarknetSignInParams {
1584
+ /** The typed data the wallet signed, as returned to the client. */
1585
+ typedData: TypedData;
1586
+ /** The wallet's `wallet_signTypedData` result (hex or decimal felts). */
1587
+ signature: Array<string | number | bigint>;
1588
+ /** Mainnet RPC (starknet.js `RpcProvider` or anything with `callContract`). */
1589
+ provider: StarknetCallProvider;
1590
+ /** What this server issued. Anything else is refused. */
1591
+ expected: {
1592
+ domain: string;
1593
+ uri: string;
1594
+ nonce: string;
1595
+ now?: number;
1596
+ };
1597
+ /**
1598
+ * The wallet's `wallet_deploymentData`, for accounts not deployed yet
1599
+ * (new Bramble/Ready accounts). Only used when the RPC says the account
1600
+ * does not exist.
1601
+ */
1602
+ deploymentData?: StarknetDeploymentData;
1603
+ }
1604
+ type StarknetSignInFailure = "MALFORMED" | "WRONG_CHAIN" | "WRONG_DOMAIN" | "WRONG_URI" | "WRONG_NONCE" | "EXPIRED" | "NOT_YET_VALID" | "INVALID_SIGNATURE" | "ACCOUNT_NOT_DEPLOYED" | "UNSUPPORTED_ACCOUNT_CLASS" | "ADDRESS_MISMATCH";
1605
+ type VerifyStarknetSignInResult = {
1606
+ ok: true;
1607
+ address: string;
1608
+ message: StarknetSignInMessage;
1609
+ } | {
1610
+ ok: false;
1611
+ reason: StarknetSignInFailure;
1612
+ };
1613
+ /**
1614
+ * Verifies a SIWS signature. The typed data is rebuilt from its message with
1615
+ * `createStarknetSignInTypedData`, so a client can't swap in other types or a
1616
+ * testnet domain; then the account is asked with `is_valid_signature`, or, if
1617
+ * it isn't deployed yet and `deploymentData` is given, checked off-chain.
1618
+ *
1619
+ * The caller still owns the nonce: issue it once, and consume it before or
1620
+ * right after calling this (never accept the same nonce twice).
1621
+ */
1622
+ declare function verifyStarknetSignIn(params: VerifyStarknetSignInParams): Promise<VerifyStarknetSignInResult>;
1623
+
1471
1624
  /**
1472
1625
  * SNIP-12 typed-data hash for `OutsideExecution` — TypeScript reference.
1473
1626
  *
@@ -3045,4 +3198,4 @@ declare class ShhhAccount {
3045
3198
  */
3046
3199
  declare function submitViaAccount(funded: Account): ShhhSubmit;
3047
3200
 
3048
- export { ANY_CALLER_FELT, APPLE_ISSUER, type AppleTokenResponse, type ApproveBody, BOOTSTRAP_DOMAIN_SEPARATOR, type BootstrapMessageParams, type BuildBootstrapSignedCallParams, type BuildMigrationCallsParams, ChipiAi, ChipiBrowserSDK, ChipiClient, ChipiPaymasterAdapter, ChipiSDK, ChipiServerSDK, ChipiSessions, ChipiSkuPurchases, ChipiSkus, ChipiTransactions, ChipiTreasury, ChipiWallets, type ComputeAddressInput, type ContractEventLog, DEFAULT_OP_EXPIRY_SECONDS, type Eip191Pubkey, type ExecuteResult, type ForTreasuryConfig, ISIGNER_CANONICAL_LABEL, ISIGNER_ID, ISRC9_V2_ID, type JwtAppleSubPubkey, type ListTreasuriesOptions, type ListTreasuriesResult, MAX_OE_VALIDITY_WINDOW_SECONDS, MIN_THRESHOLD_OWNERS, type MultisigAllowance, type NewOwnerInput, OE_DOMAIN_NAME, OE_DOMAIN_REVISION, OE_DOMAIN_VERSION, OP_ADD_OWNER, OP_REMOVE_OWNER, OP_ROTATE_OWNER, OP_SET_THRESHOLD, type OutsideExecution, type OwnerRole, type ProposeBody, ROLE_GUARDIAN, ROLE_OWNER, SIG_VERSION_V1_HEX_ASCII, SIG_VERSION_V2_SNIP12, SIG_VERSION_V2_THRESHOLD, STARKNET_MESSAGE_PREFIX, SessionTxVerifier, type SessionTxVerifierConfig, type SetTreasuryPolicyOptions, ShhhAccount, type ShhhAccountOptions, type ShhhExecuteOptions, type ShhhSignedExecution, type ShhhSubmit, type ShhhX402Wallet, TIMELOCK_SECONDS, type TreasuryPolicy, type TreasuryProposal, type TreasuryProposalSignature, type TreasurySummary, type TreasuryTransport, type TxHashStore, VIEW_SELECTORS, type VerifyTransferFailure, type VerifyTransferParams, type VerifyTransferResult, type WaitForTransactionOptions, type WaitForTransactionResult, type WebAuthnPubkey, X402Facilitator, type X402FacilitatorCreateOptions, type X402MiddlewareConfig, type X402MiddlewareFlatConfig, X402ShhhClient, type X402ShhhClientConfig, assertValidV2Snip12Envelope, buildAddSessionKeyCall, buildBootstrapSignedCall, buildCancelPendingOpCall, buildCancelRecoveryCall, buildEd25519Envelope, buildEd25519EnvelopeFromSignature, buildEip191EnvelopeFromPrivateKey, buildEip191EnvelopeFromSignature, buildExecuteAddOwnerCall, buildExecuteRemoveOwnerCall, buildExecuteRotateOwnerCall, buildExecuteSetThresholdCall, buildFinalizeRecoveryCall, buildInitiateRecoveryCall, buildJwtAppleSubEnvelopeFromTestKey, buildJwtAppleSubEnvelopeFromTokenResponse, buildMigrationCalls, buildOutsideExecution, buildProposeAddOwnerCall, buildProposeRemoveOwnerCall, buildProposeRotateOwnerCall, buildProposeSetThresholdCall, buildRemoveSpendingPolicyCall, buildRevokeSessionKeyCall, buildSessionSetupCalls, buildSetSpendingPolicyCall, buildStarkEnvelope, buildThresholdEnvelope, buildWebAuthnEnvelopeFromAssertion, buildWebAuthnEnvelopeFromPrivateKey, byteArrayToFelts, computeAddressSalt, computeBootstrapMessage, computeISignerId, computeOeHash, computeShhhAddress, computeSnip12Hash, decryptPrivateKey, ed25519OwnerId, ed25519OwnerPubkeyParam, ed25519PubkeyFelts, ed25519SignedBytes, eip191OwnerId, eip191OwnerPubkeyParam, eip191PubkeyFelts, encryptPrivateKey, estimateThresholdGasOverhead, executeShhhSponsoredRaw, hashCall, hashCalls, hashOutsideExecutionStruct, hashStarknetDomain, isReadyToExecute, isThinkDecision, jwtAppleSubHash, jwtAppleSubOwnerId, jwtAppleSubPubkeyFelts, labelToFelt, locateSubClaim, messageHashToNonceB64url, normalizeEntrypoints, ownerCommitment, parseAppleIdToken, parseDerEcdsaSignature, parseEip191Signature, parseThresholdEnvelope, resolveShhhChainId, secondsUntilExecutable, serializeExecuteFromOutsideV2Calldata, signBootstrapMessage, signTypedData, signTypedDataArray, snip12HashToHexAsciiBytes, starkOwnerId, starkPubkeyFelts, submitViaAccount, validateSpendingPolicyConfig, waitForTransaction, webauthnOwnerId, webauthnOwnerPubkeyParam, webauthnPubkeyFelts, wrapV2Snip12Envelope, wrapV2ThresholdEnvelope, x402Middleware };
3201
+ export { ANY_CALLER_FELT, APPLE_ISSUER, type AppleTokenResponse, type ApproveBody, BOOTSTRAP_DOMAIN_SEPARATOR, type BootstrapMessageParams, type BuildBootstrapSignedCallParams, type BuildMigrationCallsParams, COUNTERFACTUAL_ACCOUNT_CLASSES, ChipiAi, ChipiBrowserSDK, ChipiClient, ChipiPaymasterAdapter, ChipiSDK, ChipiServerSDK, ChipiSessions, ChipiSkuPurchases, ChipiSkus, ChipiTransactions, ChipiTreasury, ChipiWallets, type ComputeAddressInput, type ContractEventLog, DEFAULT_OP_EXPIRY_SECONDS, type Eip191Pubkey, type ExecuteResult, type ForTreasuryConfig, ISIGNER_CANONICAL_LABEL, ISIGNER_ID, ISRC9_V2_ID, type JwtAppleSubPubkey, type ListTreasuriesOptions, type ListTreasuriesResult, MAX_OE_VALIDITY_WINDOW_SECONDS, MIN_THRESHOLD_OWNERS, type MultisigAllowance, type NewOwnerInput, OE_DOMAIN_NAME, OE_DOMAIN_REVISION, OE_DOMAIN_VERSION, OP_ADD_OWNER, OP_REMOVE_OWNER, OP_ROTATE_OWNER, OP_SET_THRESHOLD, type OutsideExecution, type OwnerRole, type ProposeBody, ROLE_GUARDIAN, ROLE_OWNER, SIG_VERSION_V1_HEX_ASCII, SIG_VERSION_V2_SNIP12, SIG_VERSION_V2_THRESHOLD, SIWS_CHAIN_ID, SIWS_DOMAIN_NAME, SIWS_DOMAIN_VERSION, STARKNET_MESSAGE_PREFIX, STARKNET_SIGNATURE_VALID, SessionTxVerifier, type SessionTxVerifierConfig, type SetTreasuryPolicyOptions, ShhhAccount, type ShhhAccountOptions, type ShhhExecuteOptions, type ShhhSignedExecution, type ShhhSubmit, type ShhhX402Wallet, type StarknetCallProvider, type StarknetDeploymentData, type StarknetSignInFailure, type StarknetSignInMessage, type StarknetSignInParams, type StarknetSignatureCheck, TIMELOCK_SECONDS, type TreasuryPolicy, type TreasuryProposal, type TreasuryProposalSignature, type TreasurySummary, type TreasuryTransport, type TxHashStore, type UndeployedSignatureCheck, VIEW_SELECTORS, type VerifyStarknetSignInParams, type VerifyStarknetSignInResult, type VerifyTransferFailure, type VerifyTransferParams, type VerifyTransferResult, type WaitForTransactionOptions, type WaitForTransactionResult, type WebAuthnPubkey, X402Facilitator, type X402FacilitatorCreateOptions, type X402MiddlewareConfig, type X402MiddlewareFlatConfig, X402ShhhClient, type X402ShhhClientConfig, assertValidV2Snip12Envelope, buildAddSessionKeyCall, buildBootstrapSignedCall, buildCancelPendingOpCall, buildCancelRecoveryCall, buildEd25519Envelope, buildEd25519EnvelopeFromSignature, buildEip191EnvelopeFromPrivateKey, buildEip191EnvelopeFromSignature, buildExecuteAddOwnerCall, buildExecuteRemoveOwnerCall, buildExecuteRotateOwnerCall, buildExecuteSetThresholdCall, buildFinalizeRecoveryCall, buildInitiateRecoveryCall, buildJwtAppleSubEnvelopeFromTestKey, buildJwtAppleSubEnvelopeFromTokenResponse, buildMigrationCalls, buildOutsideExecution, buildProposeAddOwnerCall, buildProposeRemoveOwnerCall, buildProposeRotateOwnerCall, buildProposeSetThresholdCall, buildRemoveSpendingPolicyCall, buildRevokeSessionKeyCall, buildSessionSetupCalls, buildSetSpendingPolicyCall, buildStarkEnvelope, buildThresholdEnvelope, buildWebAuthnEnvelopeFromAssertion, buildWebAuthnEnvelopeFromPrivateKey, byteArrayToFelts, computeAddressSalt, computeBootstrapMessage, computeISignerId, computeOeHash, computeShhhAddress, computeSnip12Hash, createStarknetSignInTypedData, decryptPrivateKey, ed25519OwnerId, ed25519OwnerPubkeyParam, ed25519PubkeyFelts, ed25519SignedBytes, eip191OwnerId, eip191OwnerPubkeyParam, eip191PubkeyFelts, encryptPrivateKey, estimateThresholdGasOverhead, executeShhhSponsoredRaw, hashCall, hashCalls, hashOutsideExecutionStruct, hashStarknetDomain, isReadyToExecute, isThinkDecision, isValidStarknetSignature, jwtAppleSubHash, jwtAppleSubOwnerId, jwtAppleSubPubkeyFelts, labelToFelt, locateSubClaim, messageHashToNonceB64url, normalizeEntrypoints, normalizeStarknetAddress, ownerCommitment, parseAppleIdToken, parseDerEcdsaSignature, parseEip191Signature, parseThresholdEnvelope, resolveShhhChainId, secondsUntilExecutable, serializeExecuteFromOutsideV2Calldata, signBootstrapMessage, signTypedData, signTypedDataArray, snip12HashToHexAsciiBytes, starkOwnerId, starkPubkeyFelts, submitViaAccount, validateSpendingPolicyConfig, verifyStarknetSignIn, verifyUndeployedStarknetSignature, waitForTransaction, webauthnOwnerId, webauthnOwnerPubkeyParam, webauthnPubkeyFelts, wrapV2Snip12Envelope, wrapV2ThresholdEnvelope, x402Middleware };