@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/wallets.js CHANGED
@@ -248,21 +248,28 @@ async function buildEd25519Envelope(params) {
248
248
  );
249
249
  }
250
250
  const ed = await import('@noble/ed25519');
251
- const garaga = await ensureGaragaInit();
252
251
  const publicKey = await ed.getPublicKeyAsync(params.privateKey);
253
252
  const signedBytes = ed25519SignedBytes(params.messageHash);
254
253
  const signature = await ed.signAsync(signedBytes, params.privateKey);
255
- const R = signature.slice(0, 32);
256
- const s = signature.slice(32, 64);
257
- const payload = garaga.eddsaCalldataBuilder(
258
- bytesToLeBigInt(R),
259
- bytesToLeBigInt(s),
260
- bytesToLeBigInt(publicKey),
254
+ return assembleEd25519Envelope({
255
+ R: signature.slice(0, 32),
256
+ s: signature.slice(32, 64),
257
+ publicKey,
261
258
  signedBytes,
259
+ ownerIndex
260
+ });
261
+ }
262
+ async function assembleEd25519Envelope(parts) {
263
+ const garaga = await ensureGaragaInit();
264
+ const payload = garaga.eddsaCalldataBuilder(
265
+ bytesToLeBigInt(parts.R),
266
+ bytesToLeBigInt(parts.s),
267
+ bytesToLeBigInt(parts.publicKey),
268
+ parts.signedBytes,
262
269
  false
263
270
  );
264
271
  return wrapV2Snip12Envelope({
265
- ownerId: ownerIndex,
272
+ ownerId: parts.ownerIndex,
266
273
  kindTag: ED25519_KIND_TAG,
267
274
  payload
268
275
  });
@@ -790,12 +797,17 @@ var ChipiWallets = class {
790
797
  }
791
798
  const isShhh = walletType === "SHHH";
792
799
  const effectiveSignerKind = isShhh ? params.signerKind ?? "STARK" : void 0;
793
- const SDK_SHIPPED_SHHH_KINDS = ["STARK", "ED25519"];
800
+ const SDK_SHIPPED_SHHH_KINDS = [
801
+ "STARK",
802
+ "ED25519",
803
+ "WEBAUTHN_P256",
804
+ "EIP191_SECP256K1"
805
+ ];
794
806
  if (isShhh && !SDK_SHIPPED_SHHH_KINDS.includes(
795
807
  effectiveSignerKind
796
808
  )) {
797
809
  throw new Error(
798
- `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.`
810
+ `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).`
799
811
  );
800
812
  }
801
813
  const rpcUrl = walletType === "READY" ? shared.WALLET_RPC_ENDPOINTS.READY : shared.WALLET_RPC_ENDPOINTS.CHIPI;
@@ -830,6 +842,14 @@ var ChipiWallets = class {
830
842
  pubkeyFelts = ed25519PubkeyFelts(edPubKey);
831
843
  shhhPrivateKeyHex = Buffer.from(edPrivKey).toString("hex");
832
844
  }
845
+ } else if (effectiveSignerKind === "WEBAUTHN_P256" || effectiveSignerKind === "EIP191_SECP256K1") {
846
+ if (!params.ownerPubkeyFelts || params.ownerPubkeyFelts.length !== 4) {
847
+ throw new Error(
848
+ `SHHH ${effectiveSignerKind} ownerPubkeyFelts must be [x_low, x_high, y_low, y_high] (4 felts); got ${params.ownerPubkeyFelts?.length ?? 0}.`
849
+ );
850
+ }
851
+ pubkeyFelts = params.ownerPubkeyFelts.map((s) => BigInt(s));
852
+ shhhPrivateKeyHex = "";
833
853
  } else {
834
854
  throw new Error(
835
855
  `SHHH signerKind=${effectiveSignerKind} reached the address-derivation block without an implementation.`
@@ -940,12 +960,18 @@ var ChipiWallets = class {
940
960
  userSignature: userSignaturePayload,
941
961
  typedData: typedData2,
942
962
  ...encryptedPrivateKey !== void 0 && { encryptedPrivateKey },
943
- // SHHH: write the signer kind to the new wallet row. P0.3's
944
- // STARK-only path uses a Chipi-held STARK key, so
945
- // ownerPublicKey stays unset (encryptedPrivateKey carries
946
- // the same key the verifier checks against). External-rooted
947
- // wallets will pass ownerPublicKey instead in a follow-up PR.
963
+ // SHHH: write the signer kind to the new wallet row.
948
964
  ...isShhh && { signerKind: effectiveSignerKind },
965
+ // External-rooted SHHH (passkey / MetaMask / Phantom): no
966
+ // Chipi-held key, so chipi-back needs the pubkey felts (address
967
+ // derivation) + `ownerPublicKey` as the credential source it
968
+ // stores (encryptedPrivateKey stays null). Canonical
969
+ // ownerPublicKey = comma-joined felts. STARK / Chipi-held kinds
970
+ // are untouched — encryptedPrivateKey is their credential source.
971
+ ...isShhh && encryptedPrivateKey === void 0 && shhhOwnerPubkeyFelts && {
972
+ ownerPubkeyFelts: shhhOwnerPubkeyFelts,
973
+ ownerPublicKey: shhhOwnerPubkeyFelts.join(",")
974
+ },
949
975
  ...encryptedPrivateKeyBackup && { encryptedPrivateKeyBackup },
950
976
  ...params.authMethod && { authMethod: params.authMethod },
951
977
  ...params.credentialId && { credentialId: params.credentialId },