@turnkey/sdk-browser 4.3.0 → 5.0.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/CHANGELOG.md +30 -0
- package/README.md +46 -0
- package/dist/__clients__/browser-clients.d.ts +32 -43
- package/dist/__clients__/browser-clients.d.ts.map +1 -1
- package/dist/__clients__/browser-clients.js +65 -182
- package/dist/__clients__/browser-clients.js.map +1 -1
- package/dist/__clients__/browser-clients.mjs +67 -185
- package/dist/__clients__/browser-clients.mjs.map +1 -1
- package/dist/__generated__/sdk-client-base.d.ts +10 -0
- package/dist/__generated__/sdk-client-base.d.ts.map +1 -1
- package/dist/__generated__/sdk-client-base.js +367 -79
- package/dist/__generated__/sdk-client-base.js.map +1 -1
- package/dist/__generated__/sdk-client-base.mjs +367 -79
- package/dist/__generated__/sdk-client-base.mjs.map +1 -1
- package/dist/__generated__/sdk_api_types.d.ts +25 -0
- package/dist/__generated__/sdk_api_types.d.ts.map +1 -1
- package/dist/__generated__/version.d.ts +1 -1
- package/dist/__generated__/version.js +1 -1
- package/dist/__generated__/version.mjs +1 -1
- package/dist/__inputs__/public_api.types.d.ts +257 -9
- package/dist/__inputs__/public_api.types.d.ts.map +1 -1
- package/dist/__polyfills__/window.js.map +1 -1
- package/dist/__polyfills__/window.mjs.map +1 -1
- package/dist/__types__/base.d.ts +7 -66
- package/dist/__types__/base.d.ts.map +1 -1
- package/dist/__types__/base.js +1 -0
- package/dist/__types__/base.js.map +1 -1
- package/dist/__types__/base.mjs +1 -0
- package/dist/__types__/base.mjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/sdk-client.d.ts +8 -26
- package/dist/sdk-client.d.ts.map +1 -1
- package/dist/sdk-client.js +34 -92
- package/dist/sdk-client.js.map +1 -1
- package/dist/sdk-client.mjs +37 -95
- package/dist/sdk-client.mjs.map +1 -1
- package/dist/storage.d.ts +3 -20
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +0 -49
- package/dist/storage.js.map +1 -1
- package/dist/storage.mjs +1 -49
- package/dist/storage.mjs.map +1 -1
- package/dist/utils.d.ts +2 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +27 -51
- package/dist/utils.js.map +1 -1
- package/dist/utils.mjs +27 -51
- package/dist/utils.mjs.map +1 -1
- package/package.json +10 -8
package/dist/storage.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE5D,oBAAY,WAAW;IACrB,OAAO,wBAAwB;IAC/B,MAAM,oBAAoB;CAC3B;AAED,UAAU,YAAY;IACpB,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACxC,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC;CAClC;AAmBD,eAAO,MAAM,eAAe,sCACd,CAAC,KACZ,QAAQ,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS,CAKrC,CAAC;AAEF,eAAO,MAAM,eAAe,sCACd,CAAC,gBACC,YAAY,CAAC,CAAC,CAAC,KAC5B,QAAQ,GAAG,CAIb,CAAC;AAEF,eAAO,MAAM,kBAAkB,sCACjB,CAAC,KACZ,QAAQ,IAAI,CAId,CAAC;AAEF;;;;;;;GAOG;AAEH,eAAO,MAAM,YAAY,YACd,MAAM,GAAG,OAAO,WAChB,UAAU,kBAMpB,CAAC"}
|
package/dist/storage.js
CHANGED
|
@@ -4,10 +4,6 @@ var window = require('./__polyfills__/window.js');
|
|
|
4
4
|
|
|
5
5
|
exports.StorageKeys = void 0;
|
|
6
6
|
(function (StorageKeys) {
|
|
7
|
-
StorageKeys["AuthBundle"] = "@turnkey/auth_bundle";
|
|
8
|
-
StorageKeys["CurrentUser"] = "@turnkey/current_user";
|
|
9
|
-
StorageKeys["UserSession"] = "@turnkey/session/v1";
|
|
10
|
-
StorageKeys["ReadWriteSession"] = "@turnkey/read_write_session";
|
|
11
7
|
StorageKeys["Session"] = "@turnkey/session/v2";
|
|
12
8
|
StorageKeys["Client"] = "@turnkey/client";
|
|
13
9
|
})(exports.StorageKeys || (exports.StorageKeys = {}));
|
|
@@ -18,10 +14,6 @@ var StorageLocation;
|
|
|
18
14
|
StorageLocation["Session"] = "session";
|
|
19
15
|
})(StorageLocation || (StorageLocation = {}));
|
|
20
16
|
const STORAGE_VALUE_LOCATIONS = {
|
|
21
|
-
[exports.StorageKeys.AuthBundle]: StorageLocation.Secure,
|
|
22
|
-
[exports.StorageKeys.CurrentUser]: StorageLocation.Local,
|
|
23
|
-
[exports.StorageKeys.ReadWriteSession]: StorageLocation.Secure,
|
|
24
|
-
[exports.StorageKeys.UserSession]: StorageLocation.Session,
|
|
25
17
|
[exports.StorageKeys.Session]: StorageLocation.Session,
|
|
26
18
|
[exports.StorageKeys.Client]: StorageLocation.Session,
|
|
27
19
|
};
|
|
@@ -60,50 +52,9 @@ const storeSession = async (session, client) => {
|
|
|
60
52
|
await setStorageValue(exports.StorageKeys.Client, client);
|
|
61
53
|
}
|
|
62
54
|
};
|
|
63
|
-
/**
|
|
64
|
-
* Saves a user session to storage.
|
|
65
|
-
*
|
|
66
|
-
* @param {TSessionResponse} sessionResponse - The session response containing session details.
|
|
67
|
-
* @param {AuthClient} authClient - The authentication client used for the session.
|
|
68
|
-
* @throws Will throw an error if the authentication client is not set.
|
|
69
|
-
* @returns {Promise<void>} A promise that resolves when the session is saved.
|
|
70
|
-
*/
|
|
71
|
-
const saveSession = async ({ organizationId, organizationName, sessionExpiry, credentialBundle, userId, username, ...sessionResponse }, authClient) => {
|
|
72
|
-
if (!authClient) {
|
|
73
|
-
throw new Error("Failed to save session: Authentication client not set");
|
|
74
|
-
}
|
|
75
|
-
const expiry = Number(sessionExpiry);
|
|
76
|
-
const session = credentialBundle
|
|
77
|
-
? {
|
|
78
|
-
write: {
|
|
79
|
-
credentialBundle,
|
|
80
|
-
expiry,
|
|
81
|
-
},
|
|
82
|
-
}
|
|
83
|
-
: {
|
|
84
|
-
read: {
|
|
85
|
-
token: sessionResponse.session,
|
|
86
|
-
expiry,
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
const userSession = {
|
|
90
|
-
userId,
|
|
91
|
-
username,
|
|
92
|
-
organization: {
|
|
93
|
-
organizationId,
|
|
94
|
-
organizationName,
|
|
95
|
-
},
|
|
96
|
-
session: {
|
|
97
|
-
authClient,
|
|
98
|
-
...session,
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
|
-
await setStorageValue(exports.StorageKeys.UserSession, userSession);
|
|
102
|
-
};
|
|
103
55
|
|
|
104
56
|
exports.getStorageValue = getStorageValue;
|
|
105
57
|
exports.removeStorageValue = removeStorageValue;
|
|
106
|
-
exports.saveSession = saveSession;
|
|
107
58
|
exports.setStorageValue = setStorageValue;
|
|
108
59
|
exports.storeSession = storeSession;
|
|
109
60
|
//# sourceMappingURL=storage.js.map
|
package/dist/storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sources":["../src/storage.ts"],"sourcesContent":[null],"names":["StorageKeys","WindowWrapper"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"storage.js","sources":["../src/storage.ts"],"sourcesContent":[null],"names":["StorageKeys","WindowWrapper"],"mappings":";;;;AAGYA,6BAGX;AAHD,CAAA,UAAY,WAAW,EAAA;AACrB,IAAA,WAAA,CAAA,SAAA,CAAA,GAAA,qBAA+B,CAAA;AAC/B,IAAA,WAAA,CAAA,QAAA,CAAA,GAAA,iBAA0B,CAAA;AAC5B,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B,CAAC,eAAe,CAAC,CAAC;AAC3E,IAAA,sBAAsB,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;AAC3E,EAAE;MAEW,kBAAkB,GAAG,OAChC,UAAa,KACI;AACjB,IAAA,MAAM,eAAe,GAAoB,uBAAuB,CAAC,UAAU,CAAC,CAAC;AAC7E,IAAA,MAAM,sBAAsB,GAAY,iBAAiB,CAAC,eAAe,CAAC,CAAC;AAC3E,IAAA,sBAAsB,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;AAChD,EAAE;AAEF;;;;;;;AAOG;AAEU,MAAA,YAAY,GAAG,OAC1B,OAAyB,EACzB,MAAmB,KACjB;IACF,MAAM,eAAe,CAACD,mBAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACpD,IAAI,MAAM,EAAE;QACV,MAAM,eAAe,CAACA,mBAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACnD;AACH;;;;;;;"}
|
package/dist/storage.mjs
CHANGED
|
@@ -2,10 +2,6 @@ import WindowWrapper from './__polyfills__/window.mjs';
|
|
|
2
2
|
|
|
3
3
|
var StorageKeys;
|
|
4
4
|
(function (StorageKeys) {
|
|
5
|
-
StorageKeys["AuthBundle"] = "@turnkey/auth_bundle";
|
|
6
|
-
StorageKeys["CurrentUser"] = "@turnkey/current_user";
|
|
7
|
-
StorageKeys["UserSession"] = "@turnkey/session/v1";
|
|
8
|
-
StorageKeys["ReadWriteSession"] = "@turnkey/read_write_session";
|
|
9
5
|
StorageKeys["Session"] = "@turnkey/session/v2";
|
|
10
6
|
StorageKeys["Client"] = "@turnkey/client";
|
|
11
7
|
})(StorageKeys || (StorageKeys = {}));
|
|
@@ -16,10 +12,6 @@ var StorageLocation;
|
|
|
16
12
|
StorageLocation["Session"] = "session";
|
|
17
13
|
})(StorageLocation || (StorageLocation = {}));
|
|
18
14
|
const STORAGE_VALUE_LOCATIONS = {
|
|
19
|
-
[StorageKeys.AuthBundle]: StorageLocation.Secure,
|
|
20
|
-
[StorageKeys.CurrentUser]: StorageLocation.Local,
|
|
21
|
-
[StorageKeys.ReadWriteSession]: StorageLocation.Secure,
|
|
22
|
-
[StorageKeys.UserSession]: StorageLocation.Session,
|
|
23
15
|
[StorageKeys.Session]: StorageLocation.Session,
|
|
24
16
|
[StorageKeys.Client]: StorageLocation.Session,
|
|
25
17
|
};
|
|
@@ -58,46 +50,6 @@ const storeSession = async (session, client) => {
|
|
|
58
50
|
await setStorageValue(StorageKeys.Client, client);
|
|
59
51
|
}
|
|
60
52
|
};
|
|
61
|
-
/**
|
|
62
|
-
* Saves a user session to storage.
|
|
63
|
-
*
|
|
64
|
-
* @param {TSessionResponse} sessionResponse - The session response containing session details.
|
|
65
|
-
* @param {AuthClient} authClient - The authentication client used for the session.
|
|
66
|
-
* @throws Will throw an error if the authentication client is not set.
|
|
67
|
-
* @returns {Promise<void>} A promise that resolves when the session is saved.
|
|
68
|
-
*/
|
|
69
|
-
const saveSession = async ({ organizationId, organizationName, sessionExpiry, credentialBundle, userId, username, ...sessionResponse }, authClient) => {
|
|
70
|
-
if (!authClient) {
|
|
71
|
-
throw new Error("Failed to save session: Authentication client not set");
|
|
72
|
-
}
|
|
73
|
-
const expiry = Number(sessionExpiry);
|
|
74
|
-
const session = credentialBundle
|
|
75
|
-
? {
|
|
76
|
-
write: {
|
|
77
|
-
credentialBundle,
|
|
78
|
-
expiry,
|
|
79
|
-
},
|
|
80
|
-
}
|
|
81
|
-
: {
|
|
82
|
-
read: {
|
|
83
|
-
token: sessionResponse.session,
|
|
84
|
-
expiry,
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
const userSession = {
|
|
88
|
-
userId,
|
|
89
|
-
username,
|
|
90
|
-
organization: {
|
|
91
|
-
organizationId,
|
|
92
|
-
organizationName,
|
|
93
|
-
},
|
|
94
|
-
session: {
|
|
95
|
-
authClient,
|
|
96
|
-
...session,
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
await setStorageValue(StorageKeys.UserSession, userSession);
|
|
100
|
-
};
|
|
101
53
|
|
|
102
|
-
export { StorageKeys, getStorageValue, removeStorageValue,
|
|
54
|
+
export { StorageKeys, getStorageValue, removeStorageValue, setStorageValue, storeSession };
|
|
103
55
|
//# sourceMappingURL=storage.mjs.map
|
package/dist/storage.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.mjs","sources":["../src/storage.ts"],"sourcesContent":[null],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"storage.mjs","sources":["../src/storage.ts"],"sourcesContent":[null],"names":[],"mappings":";;IAGY,YAGX;AAHD,CAAA,UAAY,WAAW,EAAA;AACrB,IAAA,WAAA,CAAA,SAAA,CAAA,GAAA,qBAA+B,CAAA;AAC/B,IAAA,WAAA,CAAA,QAAA,CAAA,GAAA,iBAA0B,CAAA;AAC5B,CAAC,EAHW,WAAW,KAAX,WAAW,GAGtB,EAAA,CAAA,CAAA,CAAA;AAOD,IAAK,eAIJ,CAAA;AAJD,CAAA,UAAK,eAAe,EAAA;AAClB,IAAA,eAAA,CAAA,OAAA,CAAA,GAAA,OAAe,CAAA;AACf,IAAA,eAAA,CAAA,QAAA,CAAA,GAAA,QAAiB,CAAA;AACjB,IAAA,eAAA,CAAA,SAAA,CAAA,GAAA,SAAmB,CAAA;AACrB,CAAC,EAJI,eAAe,KAAf,eAAe,GAInB,EAAA,CAAA,CAAA,CAAA;AAED,MAAM,uBAAuB,GAAyC;AACpE,IAAA,CAAC,WAAW,CAAC,OAAO,GAAG,eAAe,CAAC,OAAO;AAC9C,IAAA,CAAC,WAAW,CAAC,MAAM,GAAG,eAAe,CAAC,OAAO;CAC9C,CAAC;AAEF,MAAM,iBAAiB,GAAG;AACxB,IAAA,CAAC,eAAe,CAAC,KAAK,GAAG,aAAa,CAAC,YAAY;AACnD,IAAA,CAAC,eAAe,CAAC,MAAM,GAAG,aAAa,CAAC,YAAY;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,8 @@
|
|
|
1
1
|
import type { EmbeddedAPIKey } from "./models";
|
|
2
|
+
import type { Session } from "@types";
|
|
2
3
|
export declare const createEmbeddedAPIKey: (targetPublicKey: string) => Promise<EmbeddedAPIKey>;
|
|
3
4
|
export declare const generateRandomBuffer: () => ArrayBuffer;
|
|
4
5
|
export declare const base64UrlEncode: (challenge: ArrayBuffer) => string;
|
|
5
6
|
export declare const bytesToHex: (bytes: Uint8Array) => string;
|
|
7
|
+
export declare function parseSession(token: string | Session): Session;
|
|
6
8
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAItC,eAAO,MAAM,oBAAoB,oBACd,MAAM,KACtB,QAAQ,cAAc,CA+DxB,CAAC;AAEF,eAAO,MAAM,oBAAoB,QAAO,WAIvC,CAAC;AAEF,eAAO,MAAM,eAAe,cAAe,WAAW,KAAG,MAMxD,CAAC;AAMF,eAAO,MAAM,UAAU,UAAW,UAAU,KAAG,MAO9C,CAAC;AAEF,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CA6B7D"}
|
package/dist/utils.js
CHANGED
|
@@ -1,57 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
require('@turnkey/encoding');
|
|
4
|
+
require('@turnkey/crypto');
|
|
5
5
|
var buffer = require('buffer');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
require('bs58check');
|
|
7
|
+
require('hpke-js');
|
|
8
|
+
require('@turnkey/api-key-stamper');
|
|
9
9
|
|
|
10
|
-
// createEmbeddedAPIKey creates an embedded API key encrypted to a target key (typically embedded within an iframe).
|
|
11
|
-
// This returns a bundle that can be decrypted by that target key, as well as the public key of the newly created API key.
|
|
12
|
-
const createEmbeddedAPIKey = async (targetPublicKey) => {
|
|
13
|
-
const TURNKEY_HPKE_INFO = new TextEncoder().encode("turnkey_hpke");
|
|
14
|
-
// 1: create new API key (to be encrypted to the targetPublicKey)
|
|
15
|
-
const p256key = crypto$1.generateP256KeyPair();
|
|
16
|
-
// 2: set up encryption
|
|
17
|
-
const suite = new hpkeJs.CipherSuite({
|
|
18
|
-
kem: hpkeJs.KemId.DhkemP256HkdfSha256,
|
|
19
|
-
kdf: hpkeJs.KdfId.HkdfSha256,
|
|
20
|
-
aead: hpkeJs.AeadId.Aes256Gcm,
|
|
21
|
-
});
|
|
22
|
-
// 3: import the targetPublicKey (i.e. passed in from the iframe)
|
|
23
|
-
const targetKeyBytes = encoding.uint8ArrayFromHexString(targetPublicKey);
|
|
24
|
-
let jwk;
|
|
25
|
-
try {
|
|
26
|
-
jwk = apiKeyStamper.pointDecode(targetKeyBytes);
|
|
27
|
-
}
|
|
28
|
-
catch (e) {
|
|
29
|
-
// provide more context about the error that is being thrown
|
|
30
|
-
throw new Error(`target public key is not a valid compressed public key: ${targetPublicKey}`);
|
|
31
|
-
}
|
|
32
|
-
const targetKey = await crypto.subtle.importKey("jwk", jwk, {
|
|
33
|
-
name: "ECDH",
|
|
34
|
-
namedCurve: "P-256",
|
|
35
|
-
}, true, []);
|
|
36
|
-
// 4: sender encrypts a message to the target key
|
|
37
|
-
const sender = await suite.createSenderContext({
|
|
38
|
-
recipientPublicKey: targetKey,
|
|
39
|
-
info: TURNKEY_HPKE_INFO,
|
|
40
|
-
});
|
|
41
|
-
const ciphertext = await sender.seal(encoding.uint8ArrayFromHexString(p256key.privateKey), crypto$1.buildAdditionalAssociatedData(new Uint8Array(sender.enc), targetKeyBytes));
|
|
42
|
-
const ciphertextUint8Array = new Uint8Array(ciphertext);
|
|
43
|
-
// 5: assemble bundle
|
|
44
|
-
const encappedKey = new Uint8Array(sender.enc);
|
|
45
|
-
const compressedEncappedKey = crypto$1.compressRawPublicKey(encappedKey);
|
|
46
|
-
const result = new Uint8Array(compressedEncappedKey.length + ciphertextUint8Array.length);
|
|
47
|
-
result.set(compressedEncappedKey);
|
|
48
|
-
result.set(ciphertextUint8Array, compressedEncappedKey.length);
|
|
49
|
-
const base58encodedBundle = bs58check.encode(result);
|
|
50
|
-
return {
|
|
51
|
-
authBundle: base58encodedBundle,
|
|
52
|
-
publicKey: p256key.publicKey,
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
10
|
const generateRandomBuffer = () => {
|
|
56
11
|
const arr = new Uint8Array(32);
|
|
57
12
|
crypto.getRandomValues(arr);
|
|
@@ -65,8 +20,29 @@ const base64UrlEncode = (challenge) => {
|
|
|
65
20
|
.replace(/=/g, "");
|
|
66
21
|
};
|
|
67
22
|
Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
23
|
+
function parseSession(token) {
|
|
24
|
+
if (typeof token !== "string") {
|
|
25
|
+
return token;
|
|
26
|
+
}
|
|
27
|
+
const [, payload] = token.split(".");
|
|
28
|
+
if (!payload) {
|
|
29
|
+
throw new Error("Invalid JWT: Missing payload");
|
|
30
|
+
}
|
|
31
|
+
const decoded = JSON.parse(atob(payload));
|
|
32
|
+
const { exp, public_key: publicKey, session_type: sessionType, user_id: userId, organization_id: organizationId, } = decoded;
|
|
33
|
+
if (!exp || !publicKey || !sessionType || !userId || !organizationId) {
|
|
34
|
+
throw new Error("JWT payload missing required fields");
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
sessionType,
|
|
38
|
+
userId,
|
|
39
|
+
organizationId,
|
|
40
|
+
expiry: exp,
|
|
41
|
+
token: publicKey,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
68
44
|
|
|
69
45
|
exports.base64UrlEncode = base64UrlEncode;
|
|
70
|
-
exports.createEmbeddedAPIKey = createEmbeddedAPIKey;
|
|
71
46
|
exports.generateRandomBuffer = generateRandomBuffer;
|
|
47
|
+
exports.parseSession = parseSession;
|
|
72
48
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../src/utils.ts"],"sourcesContent":[null],"names":["
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../src/utils.ts"],"sourcesContent":[null],"names":["Buffer"],"mappings":";;;;;;;;;AAoFO,MAAM,oBAAoB,GAAG,MAAkB;AACpD,IAAA,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;AAC/B,IAAA,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;IAC5B,OAAO,GAAG,CAAC,MAAM,CAAC;AACpB,EAAE;AAEW,MAAA,eAAe,GAAG,CAAC,SAAsB,KAAY;AAChE,IAAA,OAAOA,aAAM,CAAC,IAAI,CAAC,SAAS,CAAC;SAC1B,QAAQ,CAAC,QAAQ,CAAC;AAClB,SAAA,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;AACnB,SAAA,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;AACnB,SAAA,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AACvB,EAAE;AAEgB,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,KACjD,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAC/B;AAWI,SAAU,YAAY,CAAC,KAAuB,EAAA;AAClD,IAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AAC7B,QAAA,OAAO,KAAK,CAAC;KACd;IACD,MAAM,GAAG,OAAO,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACrC,IAAI,CAAC,OAAO,EAAE;AACZ,QAAA,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;KACjD;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1C,MAAM,EACJ,GAAG,EACH,UAAU,EAAE,SAAS,EACrB,YAAY,EAAE,WAAW,EACzB,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,cAAc,GAChC,GAAG,OAAO,CAAC;AAEZ,IAAA,IAAI,CAAC,GAAG,IAAI,CAAC,SAAS,IAAI,CAAC,WAAW,IAAI,CAAC,MAAM,IAAI,CAAC,cAAc,EAAE;AACpE,QAAA,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;KACxD;IAED,OAAO;QACL,WAAW;QACX,MAAM;QACN,cAAc;AACd,QAAA,MAAM,EAAE,GAAG;AACX,QAAA,KAAK,EAAE,SAAS;KACjB,CAAC;AACJ;;;;;;"}
|
package/dist/utils.mjs
CHANGED
|
@@ -1,55 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import '@turnkey/encoding';
|
|
2
|
+
import '@turnkey/crypto';
|
|
3
3
|
import { Buffer } from 'buffer';
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
4
|
+
import 'bs58check';
|
|
5
|
+
import 'hpke-js';
|
|
6
|
+
import '@turnkey/api-key-stamper';
|
|
7
7
|
|
|
8
|
-
// createEmbeddedAPIKey creates an embedded API key encrypted to a target key (typically embedded within an iframe).
|
|
9
|
-
// This returns a bundle that can be decrypted by that target key, as well as the public key of the newly created API key.
|
|
10
|
-
const createEmbeddedAPIKey = async (targetPublicKey) => {
|
|
11
|
-
const TURNKEY_HPKE_INFO = new TextEncoder().encode("turnkey_hpke");
|
|
12
|
-
// 1: create new API key (to be encrypted to the targetPublicKey)
|
|
13
|
-
const p256key = generateP256KeyPair();
|
|
14
|
-
// 2: set up encryption
|
|
15
|
-
const suite = new CipherSuite({
|
|
16
|
-
kem: KemId.DhkemP256HkdfSha256,
|
|
17
|
-
kdf: KdfId.HkdfSha256,
|
|
18
|
-
aead: AeadId.Aes256Gcm,
|
|
19
|
-
});
|
|
20
|
-
// 3: import the targetPublicKey (i.e. passed in from the iframe)
|
|
21
|
-
const targetKeyBytes = uint8ArrayFromHexString(targetPublicKey);
|
|
22
|
-
let jwk;
|
|
23
|
-
try {
|
|
24
|
-
jwk = pointDecode(targetKeyBytes);
|
|
25
|
-
}
|
|
26
|
-
catch (e) {
|
|
27
|
-
// provide more context about the error that is being thrown
|
|
28
|
-
throw new Error(`target public key is not a valid compressed public key: ${targetPublicKey}`);
|
|
29
|
-
}
|
|
30
|
-
const targetKey = await crypto.subtle.importKey("jwk", jwk, {
|
|
31
|
-
name: "ECDH",
|
|
32
|
-
namedCurve: "P-256",
|
|
33
|
-
}, true, []);
|
|
34
|
-
// 4: sender encrypts a message to the target key
|
|
35
|
-
const sender = await suite.createSenderContext({
|
|
36
|
-
recipientPublicKey: targetKey,
|
|
37
|
-
info: TURNKEY_HPKE_INFO,
|
|
38
|
-
});
|
|
39
|
-
const ciphertext = await sender.seal(uint8ArrayFromHexString(p256key.privateKey), buildAdditionalAssociatedData(new Uint8Array(sender.enc), targetKeyBytes));
|
|
40
|
-
const ciphertextUint8Array = new Uint8Array(ciphertext);
|
|
41
|
-
// 5: assemble bundle
|
|
42
|
-
const encappedKey = new Uint8Array(sender.enc);
|
|
43
|
-
const compressedEncappedKey = compressRawPublicKey(encappedKey);
|
|
44
|
-
const result = new Uint8Array(compressedEncappedKey.length + ciphertextUint8Array.length);
|
|
45
|
-
result.set(compressedEncappedKey);
|
|
46
|
-
result.set(ciphertextUint8Array, compressedEncappedKey.length);
|
|
47
|
-
const base58encodedBundle = bs58check.encode(result);
|
|
48
|
-
return {
|
|
49
|
-
authBundle: base58encodedBundle,
|
|
50
|
-
publicKey: p256key.publicKey,
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
8
|
const generateRandomBuffer = () => {
|
|
54
9
|
const arr = new Uint8Array(32);
|
|
55
10
|
crypto.getRandomValues(arr);
|
|
@@ -63,6 +18,27 @@ const base64UrlEncode = (challenge) => {
|
|
|
63
18
|
.replace(/=/g, "");
|
|
64
19
|
};
|
|
65
20
|
Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
21
|
+
function parseSession(token) {
|
|
22
|
+
if (typeof token !== "string") {
|
|
23
|
+
return token;
|
|
24
|
+
}
|
|
25
|
+
const [, payload] = token.split(".");
|
|
26
|
+
if (!payload) {
|
|
27
|
+
throw new Error("Invalid JWT: Missing payload");
|
|
28
|
+
}
|
|
29
|
+
const decoded = JSON.parse(atob(payload));
|
|
30
|
+
const { exp, public_key: publicKey, session_type: sessionType, user_id: userId, organization_id: organizationId, } = decoded;
|
|
31
|
+
if (!exp || !publicKey || !sessionType || !userId || !organizationId) {
|
|
32
|
+
throw new Error("JWT payload missing required fields");
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
sessionType,
|
|
36
|
+
userId,
|
|
37
|
+
organizationId,
|
|
38
|
+
expiry: exp,
|
|
39
|
+
token: publicKey,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
66
42
|
|
|
67
|
-
export { base64UrlEncode,
|
|
43
|
+
export { base64UrlEncode, generateRandomBuffer, parseSession };
|
|
68
44
|
//# sourceMappingURL=utils.mjs.map
|
package/dist/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":["../src/utils.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../src/utils.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;AAoFO,MAAM,oBAAoB,GAAG,MAAkB;AACpD,IAAA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AAC,MAAM,IAAI,CAAC,cAAc,EAAE;AACpE,QAAA,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;KACxD;IAED,OAAO;QACL,WAAW;QACX,MAAM;QACN,cAAc;AACd,QAAA,MAAM,EAAE,GAAG;AACX,QAAA,KAAK,EAAE,SAAS;KACjB,CAAC;AACJ;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turnkey/sdk-browser",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"exports": {
|
|
@@ -27,32 +27,34 @@
|
|
|
27
27
|
},
|
|
28
28
|
"repository": {
|
|
29
29
|
"type": "git",
|
|
30
|
-
"url": "https://github.com/tkhq/sdk.git",
|
|
30
|
+
"url": "git+https://github.com/tkhq/sdk.git",
|
|
31
31
|
"directory": "packages/sdk-browser"
|
|
32
32
|
},
|
|
33
33
|
"files": [
|
|
34
34
|
"dist/",
|
|
35
|
-
"CHANGELOG.md"
|
|
35
|
+
"CHANGELOG.md",
|
|
36
|
+
"README.md"
|
|
36
37
|
],
|
|
37
38
|
"publishConfig": {
|
|
38
39
|
"access": "public"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"bs58check": "
|
|
42
|
+
"bs58check": "3.0.1",
|
|
42
43
|
"buffer": "^6.0.3",
|
|
43
44
|
"cross-fetch": "^3.1.5",
|
|
44
45
|
"hpke-js": "^1.2.7",
|
|
45
46
|
"@turnkey/api-key-stamper": "0.4.5",
|
|
47
|
+
"@turnkey/encoding": "0.4.0",
|
|
46
48
|
"@turnkey/iframe-stamper": "2.5.0",
|
|
47
49
|
"@turnkey/crypto": "2.3.1",
|
|
48
|
-
"@turnkey/http": "3.
|
|
49
|
-
"@turnkey/encoding": "0.4.0",
|
|
50
|
+
"@turnkey/http": "3.4.0",
|
|
50
51
|
"@turnkey/webauthn-stamper": "0.5.0",
|
|
51
|
-
"@turnkey/wallet-stamper": "1.0.3"
|
|
52
|
+
"@turnkey/wallet-stamper": "1.0.3",
|
|
53
|
+
"@turnkey/indexed-db-stamper": "1.0.0"
|
|
52
54
|
},
|
|
53
55
|
"devDependencies": {
|
|
54
56
|
"glob": "^8.0.3",
|
|
55
|
-
"typescript": "
|
|
57
|
+
"typescript": "5.4.3"
|
|
56
58
|
},
|
|
57
59
|
"engines": {
|
|
58
60
|
"node": ">=18.0.0"
|