@theoo/sdk 0.1.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/LICENSE +21 -0
- package/README.md +81 -0
- package/dist/assurance.d.ts +14 -0
- package/dist/assurance.d.ts.map +1 -0
- package/dist/assurance.js +20 -0
- package/dist/assurance.js.map +1 -0
- package/dist/base64url.d.ts +4 -0
- package/dist/base64url.d.ts.map +1 -0
- package/dist/base64url.js +45 -0
- package/dist/base64url.js.map +1 -0
- package/dist/browser.d.ts +18 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +72 -0
- package/dist/browser.js.map +1 -0
- package/dist/client.d.ts +331 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +321 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +12 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +18 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/tokens.d.ts +21 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +12 -0
- package/dist/tokens.js.map +1 -0
- package/dist/transport.d.ts +45 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +170 -0
- package/dist/transport.js.map +1 -0
- package/dist/types.d.ts +453 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/webauthn.d.ts +34 -0
- package/dist/webauthn.d.ts.map +1 -0
- package/dist/webauthn.js +62 -0
- package/dist/webauthn.js.map +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as b64 from "./base64url.js";
|
|
2
|
+
import type { WebAuthnOptions } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Where passkey ceremonies happen. The SDK asks Theoo for options, hands
|
|
5
|
+
* them here, and sends back what comes out. Browsers use the one in
|
|
6
|
+
* `./browser`; React Native plugs in the platform's passkey API.
|
|
7
|
+
*
|
|
8
|
+
* Both methods take and return the WebAuthn *JSON* shapes (base64url byte
|
|
9
|
+
* fields), which is what Theoo speaks.
|
|
10
|
+
*/
|
|
11
|
+
export interface PasskeyProvider {
|
|
12
|
+
/** `navigator.credentials.create`, in JSON. Enrols a new passkey. */
|
|
13
|
+
create(options: WebAuthnOptions): Promise<unknown>;
|
|
14
|
+
/** `navigator.credentials.get`, in JSON. Signs a challenge with an existing passkey. */
|
|
15
|
+
get(options: WebAuthnOptions): Promise<unknown>;
|
|
16
|
+
}
|
|
17
|
+
type AnyRecord = Record<string, unknown>;
|
|
18
|
+
/** The `publicKey` half of an options document, with byte fields decoded. */
|
|
19
|
+
export declare function toCreationOptions(options: WebAuthnOptions): AnyRecord;
|
|
20
|
+
export declare function toRequestOptions(options: WebAuthnOptions): AnyRecord;
|
|
21
|
+
/**
|
|
22
|
+
* A credential as JSON, the way `PublicKeyCredential.toJSON()` renders it and
|
|
23
|
+
* the way Theoo verifies it. Handles both registration and assertion.
|
|
24
|
+
*/
|
|
25
|
+
export declare function credentialToJSON(credential: {
|
|
26
|
+
id: string;
|
|
27
|
+
rawId: ArrayBuffer;
|
|
28
|
+
type: string;
|
|
29
|
+
authenticatorAttachment?: string | null;
|
|
30
|
+
response: AnyRecord;
|
|
31
|
+
getClientExtensionResults?: () => unknown;
|
|
32
|
+
}): AnyRecord;
|
|
33
|
+
export { b64 as base64url };
|
|
34
|
+
//# sourceMappingURL=webauthn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webauthn.d.ts","sourceRoot":"","sources":["../src/webauthn.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,WAAW,eAAe;IAC9B,qEAAqE;IACrE,MAAM,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACnD,wFAAwF;IACxF,GAAG,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACjD;AAKD,KAAK,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEzC,6EAA6E;AAC7E,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,eAAe,GAAG,SAAS,CAQrE;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,eAAe,GAAG,SAAS,CAKpE;AASD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE;IAC3C,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,WAAW,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,uBAAuB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,QAAQ,EAAE,SAAS,CAAC;IACpB,yBAAyB,CAAC,EAAE,MAAM,OAAO,CAAC;CAC3C,GAAG,SAAS,CAsBZ;AAED,OAAO,EAAE,GAAG,IAAI,SAAS,EAAE,CAAC"}
|
package/dist/webauthn.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as b64 from "./base64url.js";
|
|
2
|
+
const BYTE_FIELDS_CREATE = ["challenge"];
|
|
3
|
+
const BYTE_FIELDS_GET = ["challenge"];
|
|
4
|
+
/** The `publicKey` half of an options document, with byte fields decoded. */
|
|
5
|
+
export function toCreationOptions(options) {
|
|
6
|
+
const pk = { ...(options.publicKey ?? options) };
|
|
7
|
+
for (const f of BYTE_FIELDS_CREATE)
|
|
8
|
+
if (typeof pk[f] === "string")
|
|
9
|
+
pk[f] = b64.decode(pk[f]);
|
|
10
|
+
if (pk.user && typeof pk.user.id === "string") {
|
|
11
|
+
pk.user = { ...pk.user, id: b64.decode(pk.user.id) };
|
|
12
|
+
}
|
|
13
|
+
if (Array.isArray(pk.excludeCredentials))
|
|
14
|
+
pk.excludeCredentials = decodeDescriptors(pk.excludeCredentials);
|
|
15
|
+
return pk;
|
|
16
|
+
}
|
|
17
|
+
export function toRequestOptions(options) {
|
|
18
|
+
const pk = { ...(options.publicKey ?? options) };
|
|
19
|
+
for (const f of BYTE_FIELDS_GET)
|
|
20
|
+
if (typeof pk[f] === "string")
|
|
21
|
+
pk[f] = b64.decode(pk[f]);
|
|
22
|
+
if (Array.isArray(pk.allowCredentials))
|
|
23
|
+
pk.allowCredentials = decodeDescriptors(pk.allowCredentials);
|
|
24
|
+
return pk;
|
|
25
|
+
}
|
|
26
|
+
function decodeDescriptors(list) {
|
|
27
|
+
return list.map((d) => {
|
|
28
|
+
const desc = d;
|
|
29
|
+
return typeof desc.id === "string" ? { ...desc, id: b64.decode(desc.id) } : desc;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A credential as JSON, the way `PublicKeyCredential.toJSON()` renders it and
|
|
34
|
+
* the way Theoo verifies it. Handles both registration and assertion.
|
|
35
|
+
*/
|
|
36
|
+
export function credentialToJSON(credential) {
|
|
37
|
+
const r = credential.response;
|
|
38
|
+
const response = { clientDataJSON: b64.encode(r.clientDataJSON) };
|
|
39
|
+
if (r.attestationObject) {
|
|
40
|
+
response.attestationObject = b64.encode(r.attestationObject);
|
|
41
|
+
const getTransports = r.getTransports;
|
|
42
|
+
if (typeof getTransports === "function")
|
|
43
|
+
response.transports = getTransports.call(r);
|
|
44
|
+
}
|
|
45
|
+
if (r.authenticatorData) {
|
|
46
|
+
response.authenticatorData = b64.encode(r.authenticatorData);
|
|
47
|
+
response.signature = b64.encode(r.signature);
|
|
48
|
+
response.userHandle = r.userHandle ? b64.encode(r.userHandle) : null;
|
|
49
|
+
}
|
|
50
|
+
const out = {
|
|
51
|
+
id: credential.id,
|
|
52
|
+
rawId: b64.encode(credential.rawId),
|
|
53
|
+
type: credential.type,
|
|
54
|
+
response,
|
|
55
|
+
clientExtensionResults: credential.getClientExtensionResults ? credential.getClientExtensionResults() : {},
|
|
56
|
+
};
|
|
57
|
+
if (credential.authenticatorAttachment)
|
|
58
|
+
out.authenticatorAttachment = credential.authenticatorAttachment;
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
export { b64 as base64url };
|
|
62
|
+
//# sourceMappingURL=webauthn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webauthn.js","sourceRoot":"","sources":["../src/webauthn.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAC;AAkBtC,MAAM,kBAAkB,GAAG,CAAC,WAAW,CAAU,CAAC;AAClD,MAAM,eAAe,GAAG,CAAC,WAAW,CAAU,CAAC;AAI/C,6EAA6E;AAC7E,MAAM,UAAU,iBAAiB,CAAC,OAAwB;IACxD,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,EAAe,CAAC;IAC9D,KAAK,MAAM,CAAC,IAAI,kBAAkB;QAAE,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,QAAQ;YAAE,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAW,CAAC,CAAC;IACvG,IAAI,EAAE,CAAC,IAAI,IAAI,OAAQ,EAAE,CAAC,IAAkB,CAAC,EAAE,KAAK,QAAQ,EAAE,CAAC;QAC7D,EAAE,CAAC,IAAI,GAAG,EAAE,GAAI,EAAE,CAAC,IAAkB,EAAE,EAAE,EAAE,GAAG,CAAC,MAAM,CAAE,EAAE,CAAC,IAAkB,CAAC,EAAY,CAAC,EAAE,CAAC;IAC/F,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,kBAAkB,CAAC;QAAE,EAAE,CAAC,kBAAkB,GAAG,iBAAiB,CAAC,EAAE,CAAC,kBAAkB,CAAC,CAAC;IAC3G,OAAO,EAAE,CAAC;AACZ,C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aAAa,CAAC;QAC9E,IAAI,OAAO,aAAa,KAAK,UAAU;YAAE,QAAQ,CAAC,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACvF,CAAC;IACD,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;QACxB,QAAQ,CAAC,iBAAiB,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,iBAAgC,CAAC,CAAC;QAC5E,QAAQ,CAAC,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,SAAwB,CAAC,CAAC;QAC5D,QAAQ,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,UAAyB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACtF,CAAC;IACD,MAAM,GAAG,GAAc;QACrB,EAAE,EAAE,UAAU,CAAC,EAAE;QACjB,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC;QACnC,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,QAAQ;QACR,sBAAsB,EAAE,UAAU,CAAC,yBAAyB,CAAC,CAAC,CAAC,UAAU,CAAC,yBAAyB,EAAE,CAAC,CAAC,CAAC,EAAE;KAC3G,CAAC;IACF,IAAI,UAAU,CAAC,uBAAuB;QAAE,GAAG,CAAC,uBAAuB,GAAG,UAAU,CAAC,uBAAuB,CAAC;IACzG,OAAO,GAAG,CAAC;AACb,CAAC;AAED,OAAO,EAAE,GAAG,IAAI,SAAS,EAAE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@theoo/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Theoo client: passkey-owned smart accounts, sign-in, on-chain operations, session keys and recovery, for browsers and servers.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./browser": {
|
|
15
|
+
"types": "./dist/browser.d.ts",
|
|
16
|
+
"import": "./dist/browser.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
],
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"typescript": "^5.7.0",
|
|
27
|
+
"vitest": "^3.0.0"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc -p tsconfig.build.json",
|
|
34
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
35
|
+
"test": "vitest run"
|
|
36
|
+
}
|
|
37
|
+
}
|