cilantro-sdk 0.0.18 → 0.0.20

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/helpers.cjs CHANGED
@@ -65,10 +65,10 @@ __export(helpers_exports, {
65
65
  deleteDeviceKey: () => deleteDeviceKey,
66
66
  deriveSignerKeypair: () => deriveSignerKeypair,
67
67
  detectWallets: () => detectWallets,
68
- ensureBase64URLCredentialId: () => ensureBase64URLCredentialId,
69
68
  exportToSPKI: () => exportToSPKI,
70
69
  findAndValidateDeviceKey: () => findAndValidateDeviceKey,
71
70
  findDeviceKeyByPublicKey: () => findDeviceKeyByPublicKey,
71
+ formatAuthenticationResponse: () => formatAuthenticationResponse,
72
72
  formatRegistrationResponse: () => formatRegistrationResponse,
73
73
  generateDeviceKeyPair: () => generateDeviceKeyPair,
74
74
  getBestDeviceIdentity: () => getBestDeviceIdentity,
@@ -3711,21 +3711,73 @@ function platformAuthenticatorIsAvailable() {
3711
3711
  }
3712
3712
 
3713
3713
  // src/signers/passkeyHelpers.ts
3714
- function ensureBase64URLCredentialId(credentialId) {
3715
- if (!credentialId) {
3716
- return credentialId;
3714
+ function toBase64URL(value) {
3715
+ if (typeof value === "string") {
3716
+ if (value.includes("+") || value.includes("/") || value.includes("=")) {
3717
+ return value.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
3718
+ }
3719
+ return value;
3720
+ }
3721
+ let uint8Array;
3722
+ if (Array.isArray(value)) {
3723
+ uint8Array = new Uint8Array(value);
3724
+ } else if (value instanceof ArrayBuffer) {
3725
+ uint8Array = new Uint8Array(value);
3726
+ } else {
3727
+ uint8Array = value;
3717
3728
  }
3718
- let cleaned = credentialId.replace(/=/g, "");
3719
- cleaned = cleaned.replace(/\+/g, "-").replace(/\//g, "_");
3720
- return cleaned;
3729
+ const base64 = btoa(String.fromCharCode(...uint8Array));
3730
+ return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
3731
+ }
3732
+ function isArrayBuffer(value) {
3733
+ if (Array.isArray(value))
3734
+ return true;
3735
+ if (value instanceof ArrayBuffer)
3736
+ return true;
3737
+ if (value instanceof Uint8Array)
3738
+ return true;
3739
+ return false;
3721
3740
  }
3722
3741
  function formatRegistrationResponse(response) {
3723
3742
  const formatted = { ...response };
3724
3743
  if (formatted.id) {
3725
- formatted.id = ensureBase64URLCredentialId(formatted.id);
3744
+ formatted.id = toBase64URL(formatted.id);
3745
+ }
3746
+ if (formatted.rawId) {
3747
+ formatted.rawId = toBase64URL(formatted.rawId);
3748
+ }
3749
+ if (formatted.response) {
3750
+ const formattedResponse = { ...formatted.response };
3751
+ if (isArrayBuffer(formattedResponse.clientDataJSON)) {
3752
+ formattedResponse.clientDataJSON = toBase64URL(formattedResponse.clientDataJSON);
3753
+ }
3754
+ if (isArrayBuffer(formattedResponse.attestationObject)) {
3755
+ formattedResponse.attestationObject = toBase64URL(formattedResponse.attestationObject);
3756
+ }
3757
+ formatted.response = formattedResponse;
3758
+ }
3759
+ return formatted;
3760
+ }
3761
+ function formatAuthenticationResponse(response) {
3762
+ const formatted = { ...response };
3763
+ if (formatted.id) {
3764
+ formatted.id = toBase64URL(formatted.id);
3726
3765
  }
3727
3766
  if (formatted.rawId) {
3728
- formatted.rawId = ensureBase64URLCredentialId(formatted.rawId);
3767
+ formatted.rawId = toBase64URL(formatted.rawId);
3768
+ }
3769
+ if (formatted.response) {
3770
+ const formattedResponse = { ...formatted.response };
3771
+ if (isArrayBuffer(formattedResponse.clientDataJSON)) {
3772
+ formattedResponse.clientDataJSON = toBase64URL(formattedResponse.clientDataJSON);
3773
+ }
3774
+ if (isArrayBuffer(formattedResponse.authenticatorData)) {
3775
+ formattedResponse.authenticatorData = toBase64URL(formattedResponse.authenticatorData);
3776
+ }
3777
+ if (isArrayBuffer(formattedResponse.signature)) {
3778
+ formattedResponse.signature = toBase64URL(formattedResponse.signature);
3779
+ }
3780
+ formatted.response = formattedResponse;
3729
3781
  }
3730
3782
  return formatted;
3731
3783
  }
@@ -3755,7 +3807,8 @@ async function authenticateWithPasskey(options) {
3755
3807
  throw new SDKError("WebAuthn not supported", "WEBAUTHN_NOT_SUPPORTED");
3756
3808
  }
3757
3809
  try {
3758
- return await startAuthentication(options);
3810
+ const response = await startAuthentication(options);
3811
+ return formatAuthenticationResponse(response);
3759
3812
  } catch (error) {
3760
3813
  throw new SDKError(
3761
3814
  `Passkey authentication failed: ${error instanceof Error ? error.message : String(error)}`,
@@ -3998,10 +4051,10 @@ async function signMessage2(wallet, message) {
3998
4051
  deleteDeviceKey,
3999
4052
  deriveSignerKeypair,
4000
4053
  detectWallets,
4001
- ensureBase64URLCredentialId,
4002
4054
  exportToSPKI,
4003
4055
  findAndValidateDeviceKey,
4004
4056
  findDeviceKeyByPublicKey,
4057
+ formatAuthenticationResponse,
4005
4058
  formatRegistrationResponse,
4006
4059
  generateDeviceKeyPair,
4007
4060
  getBestDeviceIdentity,