@circle-fin/daa-react-native-sdk 0.4.0 → 0.5.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/DaaReactNativeSdk.podspec +14 -8
- package/README.md +498 -24
- package/android/build.gradle +12 -7
- package/android/src/main/java/com/circle/daa/reactnative/DaaRegistrationModule.kt +1 -18
- package/android/src/main/java/com/circle/daa/reactnative/DaaSecureKeyExceptions.kt +38 -4
- package/android/src/main/java/com/circle/daa/reactnative/DaaSecureKeyModule.kt +139 -6
- package/android/src/main/java/com/circle/daa/reactnative/InstallationIdentityStore.kt +50 -1
- package/build/DaaClient.d.ts +183 -3
- package/build/DaaClient.js +296 -12
- package/build/api/AccountsClient.d.ts +3 -0
- package/build/api/AccountsClient.js +3 -0
- package/build/api/AuthClient.d.ts +17 -42
- package/build/api/AuthClient.js +26 -62
- package/build/api/ContractExecutionsClient.d.ts +114 -0
- package/build/api/ContractExecutionsClient.js +462 -0
- package/build/api/DaaUserClient.d.ts +74 -11
- package/build/api/DaaUserClient.js +84 -17
- package/build/api/TransactionsClient.d.ts +1 -1
- package/build/api/TransactionsClient.js +1 -0
- package/build/api/TransfersClient.d.ts +3 -0
- package/build/api/TransfersClient.js +3 -0
- package/build/api/WithdrawalsClient.d.ts +3 -0
- package/build/api/WithdrawalsClient.js +3 -0
- package/build/api/deviceApproval.d.ts +48 -0
- package/build/api/deviceApproval.js +247 -0
- package/build/api/deviceStatus.d.ts +61 -0
- package/build/api/deviceStatus.js +216 -0
- package/build/api/loginFailure.d.ts +10 -2
- package/build/api/loginFailure.js +33 -2
- package/build/api/signedResource.d.ts +49 -2
- package/build/api/signedResource.js +135 -36
- package/build/auth/RegistrationFlowKey.js +1 -1
- package/build/auth/daaRegistrationNative.d.ts +0 -22
- package/build/auth/daaRegistrationNative.js +3 -29
- package/build/auth/deviceAuthorization.d.ts +17 -3
- package/build/auth/deviceAuthorization.js +60 -8
- package/build/auth/registrationAuthorization.d.ts +2 -2
- package/build/auth/registrationAuthorization.js +13 -10
- package/build/config.d.ts +27 -0
- package/build/config.js +15 -0
- package/build/crypto/matchingCode.d.ts +47 -0
- package/build/crypto/matchingCode.js +93 -0
- package/build/errors.d.ts +150 -33
- package/build/errors.js +208 -47
- package/build/index.d.ts +11 -3
- package/build/models/ContractExecution.d.ts +197 -0
- package/build/models/ContractExecution.js +130 -0
- package/build/models/CreateContractExecutionRequest.d.ts +81 -0
- package/build/models/CreateContractExecutionRequest.js +19 -0
- package/build/models/DaaUserContext.d.ts +53 -3
- package/build/models/DaaUserContext.js +33 -2
- package/build/models/DeviceStatus.d.ts +69 -0
- package/build/models/DeviceStatus.js +19 -0
- package/build/models/PendingDeviceApproval.d.ts +121 -0
- package/build/models/PendingDeviceApproval.js +208 -0
- package/build/models/PendingDeviceRegistration.d.ts +162 -23
- package/build/models/PendingDeviceRegistration.js +525 -69
- package/build/models/PreparedContractExecution.d.ts +70 -0
- package/build/models/PreparedContractExecution.js +77 -0
- package/build/models/PreparedSocialLogin.d.ts +19 -26
- package/build/models/PreparedSocialLogin.js +32 -15
- package/build/models/Transaction.d.ts +48 -2
- package/build/models/Transaction.js +52 -4
- package/build/models/codeSecrets.d.ts +100 -0
- package/build/models/codeSecrets.js +321 -0
- package/build/securekey/InMemorySecureKey.d.ts +3 -1
- package/build/securekey/InMemorySecureKey.js +47 -6
- package/build/securekey/NativeSecureKey.d.ts +3 -1
- package/build/securekey/NativeSecureKey.js +204 -27
- package/build/securekey/NativeSecureKeyBridge.d.ts +72 -4
- package/build/securekey/SecureKey.d.ts +128 -8
- package/build/securekey/alias.d.ts +9 -0
- package/build/securekey/alias.js +11 -2
- package/build/securekey/ownerAuthKeyResolver.d.ts +26 -9
- package/build/securekey/ownerAuthKeyResolver.js +35 -20
- package/build/securekey/registration.d.ts +19 -0
- package/build/securekey/registration.js +38 -0
- package/build/securekey/resolveNativeBridge.d.ts +3 -0
- package/build/securekey/resolveNativeBridge.js +88 -7
- package/build/transport/headers.d.ts +11 -0
- package/build/transport/headers.js +36 -0
- package/build/wire/contractExecutionPayload.d.ts +24 -0
- package/build/wire/contractExecutionPayload.js +130 -0
- package/build/wire/daaStatusCodes.d.ts +20 -3
- package/build/wire/daaStatusCodes.js +20 -3
- package/build/wire/deviceContextPayload.d.ts +9 -7
- package/build/wire/deviceContextPayload.js +9 -7
- package/build/wire/deviceRegistrationResultPayload.d.ts +55 -10
- package/build/wire/deviceRegistrationResultPayload.js +116 -82
- package/build/wire/deviceStatusPayload.d.ts +20 -0
- package/build/wire/deviceStatusPayload.js +66 -0
- package/build/wire/instant.js +4 -1
- package/build/wire/pendingRegistrationPayload.d.ts +16 -0
- package/build/wire/pendingRegistrationPayload.js +18 -0
- package/build/wire/socialLoginRequestPayload.d.ts +0 -5
- package/build/wire/socialLoginRequestPayload.js +2 -19
- package/build/wire/transactionPayload.d.ts +2 -2
- package/build/wire/transactionPayload.js +27 -4
- package/ios/DaaRegistrationModule.swift +1 -19
- package/ios/DaaSecureKeyExceptions.swift +53 -5
- package/ios/DaaSecureKeyModule.swift +149 -5
- package/ios/InstallationIdentityStore.swift +43 -7
- package/package.json +1 -1
- package/src/DaaClient.ts +353 -15
- package/src/api/AccountsClient.ts +3 -0
- package/src/api/AuthClient.ts +33 -98
- package/src/api/ContractExecutionsClient.ts +527 -0
- package/src/api/DaaUserClient.ts +92 -17
- package/src/api/TransactionsClient.ts +1 -0
- package/src/api/TransfersClient.ts +3 -0
- package/src/api/WithdrawalsClient.ts +3 -0
- package/src/api/deviceApproval.ts +306 -0
- package/src/api/deviceStatus.ts +238 -0
- package/src/api/loginFailure.ts +39 -2
- package/src/api/signedResource.ts +206 -46
- package/src/auth/RegistrationFlowKey.ts +1 -1
- package/src/auth/daaRegistrationNative.ts +4 -49
- package/src/auth/deviceAuthorization.ts +74 -11
- package/src/auth/registrationAuthorization.ts +12 -9
- package/src/config.ts +36 -0
- package/src/crypto/matchingCode.ts +100 -0
- package/src/errors.ts +309 -52
- package/src/index.ts +36 -1
- package/src/models/ContractExecution.ts +250 -0
- package/src/models/CreateContractExecutionRequest.ts +100 -0
- package/src/models/DaaUserContext.ts +59 -3
- package/src/models/DeviceStatus.ts +50 -0
- package/src/models/PendingDeviceApproval.ts +229 -0
- package/src/models/PendingDeviceRegistration.ts +673 -79
- package/src/models/PreparedContractExecution.ts +128 -0
- package/src/models/PreparedSocialLogin.ts +41 -31
- package/src/models/Transaction.ts +77 -2
- package/src/models/codeSecrets.ts +360 -0
- package/src/securekey/InMemorySecureKey.ts +61 -7
- package/src/securekey/NativeSecureKey.ts +234 -25
- package/src/securekey/NativeSecureKeyBridge.ts +84 -4
- package/src/securekey/SecureKey.ts +138 -8
- package/src/securekey/alias.ts +11 -3
- package/src/securekey/ownerAuthKeyResolver.ts +63 -24
- package/src/securekey/registration.ts +40 -0
- package/src/securekey/resolveNativeBridge.ts +167 -9
- package/src/transport/headers.ts +47 -0
- package/src/wire/contractExecutionPayload.ts +152 -0
- package/src/wire/daaStatusCodes.ts +20 -3
- package/src/wire/deviceContextPayload.ts +9 -7
- package/src/wire/deviceRegistrationResultPayload.ts +156 -98
- package/src/wire/deviceStatusPayload.ts +68 -0
- package/src/wire/instant.ts +4 -1
- package/src/wire/pendingRegistrationPayload.ts +44 -1
- package/src/wire/socialLoginRequestPayload.ts +2 -25
- package/src/wire/transactionPayload.ts +40 -4
- package/build/auth/prepareReceipt.d.ts +0 -150
- package/build/auth/prepareReceipt.js +0 -357
- package/build/crypto/es256Jws.d.ts +0 -56
- package/build/crypto/es256Jws.js +0 -196
- package/src/auth/prepareReceipt.ts +0 -522
- package/src/crypto/es256Jws.ts +0 -240
package/build/crypto/es256Jws.js
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
4
|
-
*
|
|
5
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
-
*
|
|
7
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
-
* you may not use this file except in compliance with the License.
|
|
9
|
-
* You may obtain a copy of the License at
|
|
10
|
-
*
|
|
11
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
*
|
|
13
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
-
* See the License for the specific language governing permissions and
|
|
17
|
-
* limitations under the License.
|
|
18
|
-
*/
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.ES256_SIGNATURE_LENGTH = exports.SUPPORTED_JWS_ALGORITHMS = void 0;
|
|
21
|
-
exports.ownMember = ownMember;
|
|
22
|
-
exports.verifyCompactEs256 = verifyCompactEs256;
|
|
23
|
-
// Compact ES256 JWS verification against a pinned key set.
|
|
24
|
-
//
|
|
25
|
-
// This file does the structural work only. The signature itself is checked by
|
|
26
|
-
// the native SDKs' `DaaPrepareReceiptSignature` — CryptoKit on iOS,
|
|
27
|
-
// `java.security` on Android — through the Expo `DaaRegistration` module;
|
|
28
|
-
// there is no curve arithmetic in TypeScript.
|
|
29
|
-
// Node/Jest has no native module, so `jest.setup.js` stands in with WebCrypto,
|
|
30
|
-
// the same arrangement `crypto/random.ts` uses. A React Native host without the
|
|
31
|
-
// module fails closed.
|
|
32
|
-
//
|
|
33
|
-
// What this file enforces, and why each rule is here:
|
|
34
|
-
//
|
|
35
|
-
// - `alg` must be exactly `ES256`. It is compared against a fixed allowlist and
|
|
36
|
-
// never obeyed, which closes `alg: none` and algorithm confusion by
|
|
37
|
-
// construction.
|
|
38
|
-
// - `typ` must be the value the caller expects, so a JWS minted for another
|
|
39
|
-
// purpose under the same key does not verify as this one.
|
|
40
|
-
// - No key is ever taken from the token. `jwk`/`jku`/`x5u`/`x5c` are rejected
|
|
41
|
-
// outright, even on a token that would verify. `kid` selects among the keys
|
|
42
|
-
// the caller pinned and nothing else: an unknown `kid` is a rejection, not a
|
|
43
|
-
// fetch.
|
|
44
|
-
// - Any `crit` is rejected: this module understands no extension.
|
|
45
|
-
// - The signature must decode to exactly 64 bytes (JOSE `R || S`) before the
|
|
46
|
-
// platform is called.
|
|
47
|
-
// - The payload is parsed only after the signature verifies, so unverified
|
|
48
|
-
// claims never reach a caller.
|
|
49
|
-
//
|
|
50
|
-
// Rejections are a closed set of this module's own literals, so a caller can
|
|
51
|
-
// say why a token was refused without reflecting attacker-supplied text into a
|
|
52
|
-
// message a host app is likely to log.
|
|
53
|
-
const daaRegistrationNative_1 = require("../auth/daaRegistrationNative");
|
|
54
|
-
const errors_1 = require("../errors");
|
|
55
|
-
const base64url_1 = require("./base64url");
|
|
56
|
-
/**
|
|
57
|
-
* The one algorithm this SDK verifies. Every additional entry is another
|
|
58
|
-
* verification path, so the list holds only ES256.
|
|
59
|
-
*/
|
|
60
|
-
exports.SUPPORTED_JWS_ALGORITHMS = Object.freeze(['ES256']);
|
|
61
|
-
/** JOSE `R || S` for P-256: two 32-byte big-endian scalars. */
|
|
62
|
-
exports.ES256_SIGNATURE_LENGTH = 64;
|
|
63
|
-
/** Uncompressed SEC 1 point: `0x04 || X(32) || Y(32)`. */
|
|
64
|
-
const X963_LENGTH = 65;
|
|
65
|
-
/** Header members that carry or locate a key. Never honoured; always rejected. */
|
|
66
|
-
const KEY_SOURCING_HEADERS = Object.freeze(['jwk', 'jku', 'x5u', 'x5c']);
|
|
67
|
-
function rejected(reason) {
|
|
68
|
-
return { verified: false, reason };
|
|
69
|
-
}
|
|
70
|
-
/** Own-property read, so a name on `Object.prototype` never reads as a member. */
|
|
71
|
-
function ownMember(object, name) {
|
|
72
|
-
return Object.prototype.hasOwnProperty.call(object, name) ? object[name] : undefined;
|
|
73
|
-
}
|
|
74
|
-
/** Decode one Base64URL segment as a UTF-8 JSON object, or `null`. */
|
|
75
|
-
function decodeJsonObject(segment) {
|
|
76
|
-
let bytes;
|
|
77
|
-
try {
|
|
78
|
-
bytes = (0, base64url_1.fromBase64Url)(segment);
|
|
79
|
-
}
|
|
80
|
-
catch {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
let parsed;
|
|
84
|
-
try {
|
|
85
|
-
parsed = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes));
|
|
86
|
-
}
|
|
87
|
-
catch {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
return parsed;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Index the pinned keys by `kid`.
|
|
97
|
-
*
|
|
98
|
-
* A malformed key set is a configuration error on this side of the boundary,
|
|
99
|
-
* so it throws rather than returning a rejection that would read as a bad token.
|
|
100
|
-
*/
|
|
101
|
-
function indexPinnedKeys(keys) {
|
|
102
|
-
if (!Array.isArray(keys) || keys.length === 0) {
|
|
103
|
-
throw (0, errors_1.contractViolation)('ES256 verification requires at least one pinned key');
|
|
104
|
-
}
|
|
105
|
-
const byKid = new Map();
|
|
106
|
-
for (const key of keys) {
|
|
107
|
-
if (typeof key.kid !== 'string' || key.kid.length === 0) {
|
|
108
|
-
throw (0, errors_1.contractViolation)('every pinned ES256 key must have a non-empty kid');
|
|
109
|
-
}
|
|
110
|
-
if (byKid.has(key.kid)) {
|
|
111
|
-
throw (0, errors_1.contractViolation)('pinned ES256 keys must have distinct kids');
|
|
112
|
-
}
|
|
113
|
-
if (!(key.publicKeyX963 instanceof Uint8Array) ||
|
|
114
|
-
key.publicKeyX963.length !== X963_LENGTH ||
|
|
115
|
-
key.publicKeyX963[0] !== 0x04) {
|
|
116
|
-
throw (0, errors_1.contractViolation)('every pinned ES256 key must be an uncompressed P-256 point');
|
|
117
|
-
}
|
|
118
|
-
byKid.set(key.kid, key.publicKeyX963);
|
|
119
|
-
}
|
|
120
|
-
return byKid;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Verify a compact JWS (`header.payload.signature`) against pinned P-256 keys.
|
|
124
|
-
*
|
|
125
|
-
* Length bounds are the caller's business: a caller with a contract bound (as
|
|
126
|
-
* the Prepare receipt has) applies it first.
|
|
127
|
-
*
|
|
128
|
-
* @throws DaaError `contract_violation` for a malformed pinned key set, and when
|
|
129
|
-
* the platform verifier is unavailable or fails — including a pinned key the
|
|
130
|
-
* platform does not accept as a P-256 point. A token that is merely wrong is
|
|
131
|
-
* a `{ verified: false }` result, not a throw.
|
|
132
|
-
*/
|
|
133
|
-
async function verifyCompactEs256(jws, options) {
|
|
134
|
-
const keysByKid = indexPinnedKeys(options.keys);
|
|
135
|
-
const segments = jws.split('.');
|
|
136
|
-
if (segments.length !== 3) {
|
|
137
|
-
return rejected('malformed_compact_serialization');
|
|
138
|
-
}
|
|
139
|
-
const [encodedHeader, encodedPayload, encodedSignature] = segments;
|
|
140
|
-
if (encodedHeader === '' || encodedPayload === '' || encodedSignature === '') {
|
|
141
|
-
return rejected('malformed_compact_serialization');
|
|
142
|
-
}
|
|
143
|
-
const header = decodeJsonObject(encodedHeader);
|
|
144
|
-
if (header === null) {
|
|
145
|
-
return rejected('malformed_protected_header');
|
|
146
|
-
}
|
|
147
|
-
for (const name of KEY_SOURCING_HEADERS) {
|
|
148
|
-
if (Object.prototype.hasOwnProperty.call(header, name)) {
|
|
149
|
-
return rejected('header_sources_a_key');
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
if (Object.prototype.hasOwnProperty.call(header, 'crit')) {
|
|
153
|
-
return rejected('unsupported_critical_header');
|
|
154
|
-
}
|
|
155
|
-
const algorithm = ownMember(header, 'alg');
|
|
156
|
-
if (typeof algorithm !== 'string' || !exports.SUPPORTED_JWS_ALGORITHMS.includes(algorithm)) {
|
|
157
|
-
return rejected('unsupported_algorithm');
|
|
158
|
-
}
|
|
159
|
-
if (ownMember(header, 'typ') !== options.expectedTyp) {
|
|
160
|
-
return rejected('unexpected_type');
|
|
161
|
-
}
|
|
162
|
-
const kid = ownMember(header, 'kid');
|
|
163
|
-
if (typeof kid !== 'string' || kid.length === 0) {
|
|
164
|
-
return rejected('missing_key_id');
|
|
165
|
-
}
|
|
166
|
-
const publicKeyX963 = keysByKid.get(kid);
|
|
167
|
-
if (publicKeyX963 === undefined) {
|
|
168
|
-
return rejected('unknown_key_id');
|
|
169
|
-
}
|
|
170
|
-
let signature;
|
|
171
|
-
try {
|
|
172
|
-
signature = (0, base64url_1.fromBase64Url)(encodedSignature);
|
|
173
|
-
}
|
|
174
|
-
catch {
|
|
175
|
-
return rejected('malformed_signature');
|
|
176
|
-
}
|
|
177
|
-
if (signature.length !== exports.ES256_SIGNATURE_LENGTH) {
|
|
178
|
-
return rejected('malformed_signature');
|
|
179
|
-
}
|
|
180
|
-
// RFC 7515 §5.2: the signing input is the ASCII of the two encoded segments
|
|
181
|
-
// exactly as received, never re-encoded from the parsed header.
|
|
182
|
-
const signingInput = new TextEncoder().encode(`${encodedHeader}.${encodedPayload}`);
|
|
183
|
-
const verified = await (0, daaRegistrationNative_1.nativeVerifyPrepareReceiptSignature)((0, daaRegistrationNative_1.requireDaaRegistrationNative)(), {
|
|
184
|
-
publicKeyX963,
|
|
185
|
-
signingInput,
|
|
186
|
-
signature,
|
|
187
|
-
});
|
|
188
|
-
if (!verified) {
|
|
189
|
-
return rejected('signature_mismatch');
|
|
190
|
-
}
|
|
191
|
-
const payload = decodeJsonObject(encodedPayload);
|
|
192
|
-
if (payload === null) {
|
|
193
|
-
return rejected('malformed_payload');
|
|
194
|
-
}
|
|
195
|
-
return { verified: true, protectedHeader: header, payload };
|
|
196
|
-
}
|