@chipi-stack/backend 14.6.0 → 14.7.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.mjs CHANGED
@@ -400,21 +400,52 @@ async function buildEd25519Envelope(params) {
400
400
  );
401
401
  }
402
402
  const ed = await import('@noble/ed25519');
403
- const garaga = await ensureGaragaInit();
404
403
  const publicKey = await ed.getPublicKeyAsync(params.privateKey);
405
404
  const signedBytes = ed25519SignedBytes(params.messageHash);
406
405
  const signature = await ed.signAsync(signedBytes, params.privateKey);
407
- const R = signature.slice(0, 32);
408
- const s = signature.slice(32, 64);
409
- const payload = garaga.eddsaCalldataBuilder(
410
- bytesToLeBigInt(R),
411
- bytesToLeBigInt(s),
412
- bytesToLeBigInt(publicKey),
406
+ return assembleEd25519Envelope({
407
+ R: signature.slice(0, 32),
408
+ s: signature.slice(32, 64),
409
+ publicKey,
413
410
  signedBytes,
411
+ ownerIndex
412
+ });
413
+ }
414
+ async function buildEd25519EnvelopeFromSignature(params) {
415
+ const ownerIndex = params.ownerIndex ?? 0n;
416
+ if (ownerIndex < 0n || ownerIndex >= 0x100000000n) {
417
+ throw new Error(
418
+ `buildEd25519EnvelopeFromSignature: ownerIndex ${ownerIndex} is out of u32 range [0, 2^32). owner_id is the u32 INDEX into the wallet's owner_set (0 for primary); do NOT pass an owner_commitment or pubkey here.`
419
+ );
420
+ }
421
+ if (params.signature.length !== 64) {
422
+ throw new Error(
423
+ `Ed25519 signature must be exactly 64 bytes (R\u2016s); got ${params.signature.length}.`
424
+ );
425
+ }
426
+ if (params.publicKey.length !== 32) {
427
+ throw new Error(`Ed25519 public key must be exactly 32 bytes; got ${params.publicKey.length}.`);
428
+ }
429
+ const signedBytes = ed25519SignedBytes(params.messageHash);
430
+ return assembleEd25519Envelope({
431
+ R: params.signature.slice(0, 32),
432
+ s: params.signature.slice(32, 64),
433
+ publicKey: params.publicKey,
434
+ signedBytes,
435
+ ownerIndex
436
+ });
437
+ }
438
+ async function assembleEd25519Envelope(parts) {
439
+ const garaga = await ensureGaragaInit();
440
+ const payload = garaga.eddsaCalldataBuilder(
441
+ bytesToLeBigInt(parts.R),
442
+ bytesToLeBigInt(parts.s),
443
+ bytesToLeBigInt(parts.publicKey),
444
+ parts.signedBytes,
414
445
  false
415
446
  );
416
447
  return wrapV2Snip12Envelope({
417
- ownerId: ownerIndex,
448
+ ownerId: parts.ownerIndex,
418
449
  kindTag: ED25519_KIND_TAG,
419
450
  payload
420
451
  });
@@ -1429,12 +1460,17 @@ var ChipiWallets = class {
1429
1460
  }
1430
1461
  const isShhh = walletType === "SHHH";
1431
1462
  const effectiveSignerKind = isShhh ? params.signerKind ?? "STARK" : void 0;
1432
- const SDK_SHIPPED_SHHH_KINDS = ["STARK", "ED25519"];
1463
+ const SDK_SHIPPED_SHHH_KINDS = [
1464
+ "STARK",
1465
+ "ED25519",
1466
+ "WEBAUTHN_P256",
1467
+ "EIP191_SECP256K1"
1468
+ ];
1433
1469
  if (isShhh && !SDK_SHIPPED_SHHH_KINDS.includes(
1434
1470
  effectiveSignerKind
1435
1471
  )) {
1436
1472
  throw new Error(
1437
- `SHHH signerKind=${effectiveSignerKind} is not yet shipped from the SDK (Wave B ships STARK + ED25519). Use signerKind="STARK" or "ED25519", or wait for the follow-up PRs that add external-rooted (MetaMask, Phantom, passkey, Apple) deploy support.`
1473
+ `SHHH signerKind=${effectiveSignerKind} is not yet shipped from the SDK (supports STARK, ED25519, WEBAUTHN_P256, EIP191_SECP256K1). JWT_ES256_APPLE_SUB and others remain deferred to their follow-up PRs (OAuth / Apple-Developer context).`
1438
1474
  );
1439
1475
  }
1440
1476
  const rpcUrl = walletType === "READY" ? WALLET_RPC_ENDPOINTS.READY : WALLET_RPC_ENDPOINTS.CHIPI;
@@ -1469,6 +1505,14 @@ var ChipiWallets = class {
1469
1505
  pubkeyFelts = ed25519PubkeyFelts(edPubKey);
1470
1506
  shhhPrivateKeyHex = Buffer.from(edPrivKey).toString("hex");
1471
1507
  }
1508
+ } else if (effectiveSignerKind === "WEBAUTHN_P256" || effectiveSignerKind === "EIP191_SECP256K1") {
1509
+ if (!params.ownerPubkeyFelts || params.ownerPubkeyFelts.length !== 4) {
1510
+ throw new Error(
1511
+ `SHHH ${effectiveSignerKind} ownerPubkeyFelts must be [x_low, x_high, y_low, y_high] (4 felts); got ${params.ownerPubkeyFelts?.length ?? 0}.`
1512
+ );
1513
+ }
1514
+ pubkeyFelts = params.ownerPubkeyFelts.map((s) => BigInt(s));
1515
+ shhhPrivateKeyHex = "";
1472
1516
  } else {
1473
1517
  throw new Error(
1474
1518
  `SHHH signerKind=${effectiveSignerKind} reached the address-derivation block without an implementation.`
@@ -1579,12 +1623,18 @@ var ChipiWallets = class {
1579
1623
  userSignature: userSignaturePayload,
1580
1624
  typedData: typedData2,
1581
1625
  ...encryptedPrivateKey !== void 0 && { encryptedPrivateKey },
1582
- // SHHH: write the signer kind to the new wallet row. P0.3's
1583
- // STARK-only path uses a Chipi-held STARK key, so
1584
- // ownerPublicKey stays unset (encryptedPrivateKey carries
1585
- // the same key the verifier checks against). External-rooted
1586
- // wallets will pass ownerPublicKey instead in a follow-up PR.
1626
+ // SHHH: write the signer kind to the new wallet row.
1587
1627
  ...isShhh && { signerKind: effectiveSignerKind },
1628
+ // External-rooted SHHH (passkey / MetaMask / Phantom): no
1629
+ // Chipi-held key, so chipi-back needs the pubkey felts (address
1630
+ // derivation) + `ownerPublicKey` as the credential source it
1631
+ // stores (encryptedPrivateKey stays null). Canonical
1632
+ // ownerPublicKey = comma-joined felts. STARK / Chipi-held kinds
1633
+ // are untouched — encryptedPrivateKey is their credential source.
1634
+ ...isShhh && encryptedPrivateKey === void 0 && shhhOwnerPubkeyFelts && {
1635
+ ownerPubkeyFelts: shhhOwnerPubkeyFelts,
1636
+ ownerPublicKey: shhhOwnerPubkeyFelts.join(",")
1637
+ },
1588
1638
  ...encryptedPrivateKeyBackup && { encryptedPrivateKeyBackup },
1589
1639
  ...params.authMethod && { authMethod: params.authMethod },
1590
1640
  ...params.credentialId && { credentialId: params.credentialId },
@@ -3185,9 +3235,7 @@ var ChipiSDK = class {
3185
3235
  * });
3186
3236
  * ```
3187
3237
  */
3188
- async signTypedData({
3189
- params
3190
- }) {
3238
+ async signTypedData({ params }) {
3191
3239
  return signTypedData({ params });
3192
3240
  }
3193
3241
  /**
@@ -4489,6 +4537,6 @@ function secondsUntilExecutable(validAfterSecs, nowSecs) {
4489
4537
  init_threshold();
4490
4538
  init_execute_paymaster_raw();
4491
4539
 
4492
- export { ANY_CALLER_FELT, APPLE_ISSUER, BOOTSTRAP_DOMAIN_SEPARATOR, ChipiBrowserSDK, ChipiClient, ChipiPaymasterAdapter, ChipiSDK, ChipiServerSDK, ChipiSessions, ChipiSkuPurchases, ChipiSkus, ChipiTransactions, ChipiWallets, DEFAULT_OP_EXPIRY_SECONDS, ISIGNER_CANONICAL_LABEL, ISIGNER_ID, ISRC9_V2_ID, MAX_OE_VALIDITY_WINDOW_SECONDS, MIN_THRESHOLD_OWNERS, OE_DOMAIN_NAME, OE_DOMAIN_REVISION, OE_DOMAIN_VERSION, OP_ADD_OWNER, OP_REMOVE_OWNER, OP_ROTATE_OWNER, OP_SET_THRESHOLD, ROLE_GUARDIAN, ROLE_OWNER, SIG_VERSION_V1_HEX_ASCII, SIG_VERSION_V2_SNIP12, SIG_VERSION_V2_THRESHOLD, STARKNET_MESSAGE_PREFIX, TIMELOCK_SECONDS, VIEW_SELECTORS, X402Facilitator, X402ShhhClient, assertValidV2Snip12Envelope, buildBootstrapSignedCall, buildCancelPendingOpCall, buildCancelRecoveryCall, buildEd25519Envelope, buildEip191EnvelopeFromPrivateKey, buildEip191EnvelopeFromSignature, buildExecuteAddOwnerCall, buildExecuteRemoveOwnerCall, buildExecuteRotateOwnerCall, buildExecuteSetThresholdCall, buildFinalizeRecoveryCall, buildInitiateRecoveryCall, buildJwtAppleSubEnvelopeFromTestKey, buildJwtAppleSubEnvelopeFromTokenResponse, buildMigrationCalls, buildOutsideExecution, buildProposeAddOwnerCall, buildProposeRemoveOwnerCall, buildProposeRotateOwnerCall, buildProposeSetThresholdCall, buildStarkEnvelope, buildThresholdEnvelope, buildWebAuthnEnvelopeFromAssertion, buildWebAuthnEnvelopeFromPrivateKey, byteArrayToFelts, computeAddressSalt, computeBootstrapMessage, computeISignerId, computeOeHash, computeShhhAddress, computeSnip12Hash, decryptPrivateKey, ed25519OwnerId, ed25519PubkeyFelts, ed25519SignedBytes, eip191OwnerId, eip191PubkeyFelts, encryptPrivateKey, estimateThresholdGasOverhead, executeShhhSponsoredRaw, hashCall, hashCalls, hashOutsideExecutionStruct, hashStarknetDomain, isReadyToExecute, jwtAppleSubHash, jwtAppleSubOwnerId, jwtAppleSubPubkeyFelts, labelToFelt, locateSubClaim, messageHashToNonceB64url, migrateChipiWalletToShhh, ownerCommitment, parseAppleIdToken, parseDerEcdsaSignature, parseEip191Signature, parseThresholdEnvelope, resolveShhhChainId, secondsUntilExecutable, serializeExecuteFromOutsideV2Calldata, signBootstrapMessage, signTypedData, snip12HashToHexAsciiBytes, starkOwnerId, starkPubkeyFelts, webauthnOwnerId, webauthnPubkeyFelts, wrapV2Snip12Envelope, wrapV2ThresholdEnvelope, x402Middleware };
4540
+ export { ANY_CALLER_FELT, APPLE_ISSUER, BOOTSTRAP_DOMAIN_SEPARATOR, ChipiBrowserSDK, ChipiClient, ChipiPaymasterAdapter, ChipiSDK, ChipiServerSDK, ChipiSessions, ChipiSkuPurchases, ChipiSkus, ChipiTransactions, ChipiWallets, DEFAULT_OP_EXPIRY_SECONDS, ISIGNER_CANONICAL_LABEL, ISIGNER_ID, ISRC9_V2_ID, MAX_OE_VALIDITY_WINDOW_SECONDS, MIN_THRESHOLD_OWNERS, OE_DOMAIN_NAME, OE_DOMAIN_REVISION, OE_DOMAIN_VERSION, OP_ADD_OWNER, OP_REMOVE_OWNER, OP_ROTATE_OWNER, OP_SET_THRESHOLD, ROLE_GUARDIAN, ROLE_OWNER, SIG_VERSION_V1_HEX_ASCII, SIG_VERSION_V2_SNIP12, SIG_VERSION_V2_THRESHOLD, STARKNET_MESSAGE_PREFIX, TIMELOCK_SECONDS, VIEW_SELECTORS, X402Facilitator, X402ShhhClient, assertValidV2Snip12Envelope, buildBootstrapSignedCall, buildCancelPendingOpCall, buildCancelRecoveryCall, buildEd25519Envelope, buildEd25519EnvelopeFromSignature, buildEip191EnvelopeFromPrivateKey, buildEip191EnvelopeFromSignature, buildExecuteAddOwnerCall, buildExecuteRemoveOwnerCall, buildExecuteRotateOwnerCall, buildExecuteSetThresholdCall, buildFinalizeRecoveryCall, buildInitiateRecoveryCall, buildJwtAppleSubEnvelopeFromTestKey, buildJwtAppleSubEnvelopeFromTokenResponse, buildMigrationCalls, buildOutsideExecution, buildProposeAddOwnerCall, buildProposeRemoveOwnerCall, buildProposeRotateOwnerCall, buildProposeSetThresholdCall, buildStarkEnvelope, buildThresholdEnvelope, buildWebAuthnEnvelopeFromAssertion, buildWebAuthnEnvelopeFromPrivateKey, byteArrayToFelts, computeAddressSalt, computeBootstrapMessage, computeISignerId, computeOeHash, computeShhhAddress, computeSnip12Hash, decryptPrivateKey, ed25519OwnerId, ed25519PubkeyFelts, ed25519SignedBytes, eip191OwnerId, eip191PubkeyFelts, encryptPrivateKey, estimateThresholdGasOverhead, executeShhhSponsoredRaw, hashCall, hashCalls, hashOutsideExecutionStruct, hashStarknetDomain, isReadyToExecute, jwtAppleSubHash, jwtAppleSubOwnerId, jwtAppleSubPubkeyFelts, labelToFelt, locateSubClaim, messageHashToNonceB64url, migrateChipiWalletToShhh, ownerCommitment, parseAppleIdToken, parseDerEcdsaSignature, parseEip191Signature, parseThresholdEnvelope, resolveShhhChainId, secondsUntilExecutable, serializeExecuteFromOutsideV2Calldata, signBootstrapMessage, signTypedData, snip12HashToHexAsciiBytes, starkOwnerId, starkPubkeyFelts, webauthnOwnerId, webauthnPubkeyFelts, wrapV2Snip12Envelope, wrapV2ThresholdEnvelope, x402Middleware };
4493
4541
  //# sourceMappingURL=index.mjs.map
4494
4542
  //# sourceMappingURL=index.mjs.map