@chipi-stack/backend 14.6.0 → 14.8.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/wallets.mjs CHANGED
@@ -242,21 +242,28 @@ async function buildEd25519Envelope(params) {
242
242
  );
243
243
  }
244
244
  const ed = await import('@noble/ed25519');
245
- const garaga = await ensureGaragaInit();
246
245
  const publicKey = await ed.getPublicKeyAsync(params.privateKey);
247
246
  const signedBytes = ed25519SignedBytes(params.messageHash);
248
247
  const signature = await ed.signAsync(signedBytes, params.privateKey);
249
- const R = signature.slice(0, 32);
250
- const s = signature.slice(32, 64);
251
- const payload = garaga.eddsaCalldataBuilder(
252
- bytesToLeBigInt(R),
253
- bytesToLeBigInt(s),
254
- bytesToLeBigInt(publicKey),
248
+ return assembleEd25519Envelope({
249
+ R: signature.slice(0, 32),
250
+ s: signature.slice(32, 64),
251
+ publicKey,
255
252
  signedBytes,
253
+ ownerIndex
254
+ });
255
+ }
256
+ async function assembleEd25519Envelope(parts) {
257
+ const garaga = await ensureGaragaInit();
258
+ const payload = garaga.eddsaCalldataBuilder(
259
+ bytesToLeBigInt(parts.R),
260
+ bytesToLeBigInt(parts.s),
261
+ bytesToLeBigInt(parts.publicKey),
262
+ parts.signedBytes,
256
263
  false
257
264
  );
258
265
  return wrapV2Snip12Envelope({
259
- ownerId: ownerIndex,
266
+ ownerId: parts.ownerIndex,
260
267
  kindTag: ED25519_KIND_TAG,
261
268
  payload
262
269
  });
@@ -784,12 +791,17 @@ var ChipiWallets = class {
784
791
  }
785
792
  const isShhh = walletType === "SHHH";
786
793
  const effectiveSignerKind = isShhh ? params.signerKind ?? "STARK" : void 0;
787
- const SDK_SHIPPED_SHHH_KINDS = ["STARK", "ED25519"];
794
+ const SDK_SHIPPED_SHHH_KINDS = [
795
+ "STARK",
796
+ "ED25519",
797
+ "WEBAUTHN_P256",
798
+ "EIP191_SECP256K1"
799
+ ];
788
800
  if (isShhh && !SDK_SHIPPED_SHHH_KINDS.includes(
789
801
  effectiveSignerKind
790
802
  )) {
791
803
  throw new Error(
792
- `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.`
804
+ `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).`
793
805
  );
794
806
  }
795
807
  const rpcUrl = walletType === "READY" ? WALLET_RPC_ENDPOINTS.READY : WALLET_RPC_ENDPOINTS.CHIPI;
@@ -824,6 +836,14 @@ var ChipiWallets = class {
824
836
  pubkeyFelts = ed25519PubkeyFelts(edPubKey);
825
837
  shhhPrivateKeyHex = Buffer.from(edPrivKey).toString("hex");
826
838
  }
839
+ } else if (effectiveSignerKind === "WEBAUTHN_P256" || effectiveSignerKind === "EIP191_SECP256K1") {
840
+ if (!params.ownerPubkeyFelts || params.ownerPubkeyFelts.length !== 4) {
841
+ throw new Error(
842
+ `SHHH ${effectiveSignerKind} ownerPubkeyFelts must be [x_low, x_high, y_low, y_high] (4 felts); got ${params.ownerPubkeyFelts?.length ?? 0}.`
843
+ );
844
+ }
845
+ pubkeyFelts = params.ownerPubkeyFelts.map((s) => BigInt(s));
846
+ shhhPrivateKeyHex = "";
827
847
  } else {
828
848
  throw new Error(
829
849
  `SHHH signerKind=${effectiveSignerKind} reached the address-derivation block without an implementation.`
@@ -934,12 +954,18 @@ var ChipiWallets = class {
934
954
  userSignature: userSignaturePayload,
935
955
  typedData: typedData2,
936
956
  ...encryptedPrivateKey !== void 0 && { encryptedPrivateKey },
937
- // SHHH: write the signer kind to the new wallet row. P0.3's
938
- // STARK-only path uses a Chipi-held STARK key, so
939
- // ownerPublicKey stays unset (encryptedPrivateKey carries
940
- // the same key the verifier checks against). External-rooted
941
- // wallets will pass ownerPublicKey instead in a follow-up PR.
957
+ // SHHH: write the signer kind to the new wallet row.
942
958
  ...isShhh && { signerKind: effectiveSignerKind },
959
+ // External-rooted SHHH (passkey / MetaMask / Phantom): no
960
+ // Chipi-held key, so chipi-back needs the pubkey felts (address
961
+ // derivation) + `ownerPublicKey` as the credential source it
962
+ // stores (encryptedPrivateKey stays null). Canonical
963
+ // ownerPublicKey = comma-joined felts. STARK / Chipi-held kinds
964
+ // are untouched — encryptedPrivateKey is their credential source.
965
+ ...isShhh && encryptedPrivateKey === void 0 && shhhOwnerPubkeyFelts && {
966
+ ownerPubkeyFelts: shhhOwnerPubkeyFelts,
967
+ ownerPublicKey: shhhOwnerPubkeyFelts.join(",")
968
+ },
943
969
  ...encryptedPrivateKeyBackup && { encryptedPrivateKeyBackup },
944
970
  ...params.authMethod && { authMethod: params.authMethod },
945
971
  ...params.credentialId && { credentialId: params.credentialId },