@x402/extensions 2.3.0 → 2.3.1

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.
@@ -1,5 +1,5 @@
1
1
  export { B as BAZAAR, a as BazaarClientExtension, b as BodyDiscoveryExtension, c as BodyDiscoveryInfo, D as DiscoveredResource, d as DiscoveryExtension, e as DiscoveryInfo, f as DiscoveryResource, g as DiscoveryResourcesResponse, L as ListDiscoveryResourcesParams, Q as QueryDiscoveryExtension, h as QueryDiscoveryInfo, V as ValidationResult, W as WithExtensions, i as bazaarResourceServerExtension, j as declareDiscoveryExtension, k as extractDiscoveryInfo, l as extractDiscoveryInfoFromExtension, m as extractDiscoveryInfoV1, n as extractResourceMetadataV1, o as isDiscoverableV1, v as validateAndExtract, p as validateDiscoveryExtension, w as withBazaar } from './index-DvDlinmy.js';
2
- export { CompleteSIWxInfo, CreateSIWxHookOptions, DeclareSIWxOptions, EVMMessageVerifier, EVMSigner, InMemorySIWxStorage, SIGN_IN_WITH_X, SIWxExtension, SIWxExtensionInfo, SIWxExtensionSchema, SIWxHookEvent, SIWxPayload, SIWxPayloadSchema, SIWxSigner, SIWxStorage, SIWxValidationOptions, SIWxValidationResult, SIWxVerifyOptions, SIWxVerifyResult, SOLANA_DEVNET, SOLANA_MAINNET, SOLANA_TESTNET, SignatureScheme, SignatureType, SolanaSigner, SupportedChain, buildSIWxSchema, createSIWxClientHook, createSIWxMessage, createSIWxPayload, createSIWxRequestHook, createSIWxSettleHook, declareSIWxExtension, decodeBase58, encodeBase58, encodeSIWxHeader, extractEVMChainId, extractSolanaChainReference, formatSIWEMessage, formatSIWSMessage, getEVMAddress, getSolanaAddress, parseSIWxHeader, signEVMMessage, signSolanaMessage, siwxResourceServerExtension, validateSIWxMessage, verifyEVMSignature, verifySIWxSignature, verifySolanaSignature, wrapFetchWithSIWx } from './sign-in-with-x/index.js';
2
+ export { CompleteSIWxInfo, CreateSIWxHookOptions, DeclareSIWxOptions, EVMMessageVerifier, EVMSigner, InMemorySIWxStorage, SIGN_IN_WITH_X, SIWxExtension, SIWxExtensionInfo, SIWxExtensionSchema, SIWxHookEvent, SIWxPayload, SIWxPayloadSchema, SIWxSigner, SIWxStorage, SIWxValidationOptions, SIWxValidationResult, SIWxVerifyOptions, SIWxVerifyResult, SOLANA_DEVNET, SOLANA_MAINNET, SOLANA_TESTNET, SignatureScheme, SignatureType, SolanaSigner, SupportedChain, buildSIWxSchema, createSIWxClientHook, createSIWxMessage, createSIWxPayload, createSIWxRequestHook, createSIWxSettleHook, declareSIWxExtension, decodeBase58, encodeBase58, encodeSIWxHeader, extractEVMChainId, extractSolanaChainReference, formatSIWEMessage, formatSIWSMessage, getEVMAddress, getSolanaAddress, isEVMSigner, isSolanaSigner, parseSIWxHeader, signEVMMessage, signSolanaMessage, siwxResourceServerExtension, validateSIWxMessage, verifyEVMSignature, verifySIWxSignature, verifySolanaSignature, wrapFetchWithSIWx } from './sign-in-with-x/index.js';
3
3
  export { PAYMENT_IDENTIFIER, PAYMENT_ID_MAX_LENGTH, PAYMENT_ID_MIN_LENGTH, PAYMENT_ID_PATTERN, PaymentIdentifierExtension, PaymentIdentifierInfo, PaymentIdentifierSchema, PaymentIdentifierValidationResult, appendPaymentIdentifierToExtensions, declarePaymentIdentifierExtension, extractAndValidatePaymentIdentifier, extractPaymentIdentifier, generatePaymentId, hasPaymentIdentifier, isPaymentIdentifierExtension, isPaymentIdentifierRequired, isValidPaymentId, paymentIdentifierResourceServerExtension, paymentIdentifierSchema, validatePaymentIdentifier, validatePaymentIdentifierRequirement } from './payment-identifier/index.js';
4
4
  import '@x402/core/http';
5
5
  import '@x402/core/types';
package/dist/cjs/index.js CHANGED
@@ -70,8 +70,10 @@ __export(src_exports, {
70
70
  getSolanaAddress: () => getSolanaAddress,
71
71
  hasPaymentIdentifier: () => hasPaymentIdentifier,
72
72
  isDiscoverableV1: () => isDiscoverableV1,
73
+ isEVMSigner: () => isEVMSigner,
73
74
  isPaymentIdentifierExtension: () => isPaymentIdentifierExtension,
74
75
  isPaymentIdentifierRequired: () => isPaymentIdentifierRequired,
76
+ isSolanaSigner: () => isSolanaSigner,
75
77
  isValidPaymentId: () => isValidPaymentId,
76
78
  parseSIWxHeader: () => parseSIWxHeader,
77
79
  paymentIdentifierResourceServerExtension: () => paymentIdentifierResourceServerExtension,
@@ -620,6 +622,21 @@ function decodeBase58(encoded) {
620
622
  function encodeBase58(bytes) {
621
623
  return import_base.base58.encode(bytes);
622
624
  }
625
+ function isSolanaSigner(signer) {
626
+ if ("signMessages" in signer && typeof signer.signMessages === "function") {
627
+ return true;
628
+ }
629
+ if ("publicKey" in signer && signer.publicKey) {
630
+ const pk = signer.publicKey;
631
+ if (typeof pk === "object" && pk !== null && "toBase58" in pk) {
632
+ return true;
633
+ }
634
+ if (typeof pk === "string" && !pk.startsWith("0x")) {
635
+ return true;
636
+ }
637
+ }
638
+ return false;
639
+ }
623
640
 
624
641
  // src/sign-in-with-x/schema.ts
625
642
  function buildSIWxSchema() {
@@ -884,6 +901,30 @@ async function verifyEVMSignature(message, address, signature, verifier) {
884
901
  }
885
902
  return (0, import_viem.verifyMessage)(args);
886
903
  }
904
+ function isEVMSigner(signer) {
905
+ if ("signMessages" in signer && typeof signer.signMessages === "function") {
906
+ return false;
907
+ }
908
+ if ("publicKey" in signer && signer.publicKey) {
909
+ const pk = signer.publicKey;
910
+ if (typeof pk === "object" && pk !== null && "toBase58" in pk) {
911
+ return false;
912
+ }
913
+ if (typeof pk === "string" && !pk.startsWith("0x")) {
914
+ return false;
915
+ }
916
+ }
917
+ if ("account" in signer && signer.account && typeof signer.account === "object") {
918
+ const account = signer.account;
919
+ if (account.address && account.address.startsWith("0x")) {
920
+ return true;
921
+ }
922
+ }
923
+ if ("address" in signer && typeof signer.address === "string" && signer.address.startsWith("0x")) {
924
+ return true;
925
+ }
926
+ return false;
927
+ }
887
928
 
888
929
  // src/sign-in-with-x/verify.ts
889
930
  async function verifySIWxSignature(payload, options) {
@@ -1020,8 +1061,14 @@ function getEVMAddress(signer) {
1020
1061
  throw new Error("EVM signer missing address");
1021
1062
  }
1022
1063
  function getSolanaAddress(signer) {
1023
- const pk = signer.publicKey;
1024
- return typeof pk === "string" ? pk : pk.toBase58();
1064
+ if ("address" in signer && signer.address) {
1065
+ return signer.address;
1066
+ }
1067
+ if ("publicKey" in signer) {
1068
+ const pk = signer.publicKey;
1069
+ return typeof pk === "string" ? pk : pk.toBase58();
1070
+ }
1071
+ throw new Error("Solana signer missing address or publicKey");
1025
1072
  }
1026
1073
  async function signEVMMessage(message, signer) {
1027
1074
  if (signer.account) {
@@ -1031,8 +1078,17 @@ async function signEVMMessage(message, signer) {
1031
1078
  }
1032
1079
  async function signSolanaMessage(message, signer) {
1033
1080
  const messageBytes = new TextEncoder().encode(message);
1034
- const signatureBytes = await signer.signMessage(messageBytes);
1035
- return encodeBase58(signatureBytes);
1081
+ if ("signMessages" in signer) {
1082
+ const results = await signer.signMessages([{ content: messageBytes, signatures: {} }]);
1083
+ const sigDict = results[0];
1084
+ const signatureBytes = Object.values(sigDict)[0];
1085
+ return encodeBase58(signatureBytes);
1086
+ }
1087
+ if ("signMessage" in signer) {
1088
+ const signatureBytes = await signer.signMessage(messageBytes);
1089
+ return encodeBase58(signatureBytes);
1090
+ }
1091
+ throw new Error("Solana signer missing signMessage or signMessages method");
1036
1092
  }
1037
1093
 
1038
1094
  // src/sign-in-with-x/client.ts
@@ -1205,15 +1261,15 @@ function createSIWxRequestHook(options) {
1205
1261
  };
1206
1262
  }
1207
1263
  function createSIWxClientHook(signer) {
1264
+ const signerIsSolana = isSolanaSigner(signer);
1265
+ const expectedSignatureType = signerIsSolana ? "ed25519" : "eip191";
1208
1266
  return async (context) => {
1209
1267
  const extensions = context.paymentRequired.extensions ?? {};
1210
1268
  const siwxExtension = extensions[SIGN_IN_WITH_X];
1211
1269
  if (!siwxExtension?.supportedChains) return;
1212
1270
  try {
1213
- const paymentNetwork = context.paymentRequired.accepts?.[0]?.network;
1214
- if (!paymentNetwork) return;
1215
1271
  const matchingChain = siwxExtension.supportedChains.find(
1216
- (chain) => chain.chainId === paymentNetwork
1272
+ (chain) => chain.type === expectedSignatureType
1217
1273
  );
1218
1274
  if (!matchingChain) {
1219
1275
  return;
@@ -1485,8 +1541,10 @@ var paymentIdentifierResourceServerExtension = {
1485
1541
  getSolanaAddress,
1486
1542
  hasPaymentIdentifier,
1487
1543
  isDiscoverableV1,
1544
+ isEVMSigner,
1488
1545
  isPaymentIdentifierExtension,
1489
1546
  isPaymentIdentifierRequired,
1547
+ isSolanaSigner,
1490
1548
  isValidPaymentId,
1491
1549
  parseSIWxHeader,
1492
1550
  paymentIdentifierResourceServerExtension,