kokio-sdk 0.1.1 → 0.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kokio-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/esm/config.js",
@@ -39,6 +39,7 @@
39
39
  "@account-kit/core": "^4.13.0",
40
40
  "@account-kit/infra": "^4.15.3",
41
41
  "@account-kit/signer": "^4.14.0",
42
+ "@noble/curves": "^2.2.0",
42
43
  "@peculiar/asn1-ecc": "^2.3.15",
43
44
  "@peculiar/asn1-schema": "^2.3.15",
44
45
  "@simplewebauthn/server": "^13.1.1",
@@ -54,6 +54,7 @@ export const _stamp = async (credentialId: string, rpId: string, payload: Hex):
54
54
  } catch (e) {
55
55
  console.log("Failed to get authenticationResult");
56
56
  console.error(JSON.stringify(e, Object.getOwnPropertyNames(e)))
57
+ throw e;
57
58
  }
58
59
 
59
60
  // See https://github.com/f-23/react-native-passkey/issues/54
@@ -75,11 +76,16 @@ export const _stamp = async (credentialId: string, rpId: string, payload: Hex):
75
76
  const typeSearchString = '"type":"webauthn.get"';
76
77
  const challengeSearchString = '"challenge":';
77
78
 
78
- const typeIndex = clientDataJSONString.indexOf(typeSearchString);
79
+ const rawTypeIndex = clientDataJSONString.indexOf(typeSearchString);
79
80
  const challengeIndex = clientDataJSONString.indexOf(challengeSearchString);
80
81
 
81
- if (typeIndex === -1) {
82
- console.warn(`Warning: Could not find type substring '${typeSearchString}' in clientDataJSON. Setting typeIndex to 0.`);
82
+ let typeIndex = rawTypeIndex;
83
+ if (rawTypeIndex === -1) {
84
+ console.warn("typeIndex not found", {
85
+ expected: typeSearchString,
86
+ clientDataSnippet: clientDataJSONString.slice(0, 200),
87
+ });
88
+ typeIndex = 0;
83
89
  }
84
90
  if (challengeIndex === -1) {
85
91
  throw new Error(`Could not find challenge substring '${challengeSearchString}' in clientDataJSON for index calculation.`);
@@ -91,10 +97,22 @@ export const _stamp = async (credentialId: string, rpId: string, payload: Hex):
91
97
 
92
98
  // 4. Decode signature (ASN.1 DER encoded)
93
99
  const signatureBytes = isoBase64URL.toBuffer(signature);
94
- let parsedSignature = p256.Signature.fromDER(signatureBytes);
95
- parsedSignature = parsedSignature.normalizeS();
96
- let r = parsedSignature.r;
97
- let s = parsedSignature.s;
100
+ // let parsedSignature = p256.Signature.fromDER(signatureBytes);
101
+ let parsedSignature = p256.Signature.fromBytes(
102
+ signatureBytes instanceof Uint8Array
103
+ ? signatureBytes
104
+ : new Uint8Array(signatureBytes),
105
+ "der"
106
+ );
107
+
108
+ // Normalize s
109
+ const n = p256.Point.CURVE().n;
110
+ const halfN = n >> 1n;
111
+
112
+ const r = parsedSignature.r;
113
+ const s = parsedSignature.s > halfN
114
+ ? n - parsedSignature.s
115
+ : parsedSignature.s;
98
116
 
99
117
  const webAuthnSig = {
100
118
  authenticatorData: authenticatorDataHex,