@mysten/enoki 0.7.1 → 0.8.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 +7 -0
- package/dist/cjs/index.d.ts +3 -1
- package/dist/cjs/index.js +4 -2
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/wallet/initializer.d.ts +11 -0
- package/dist/cjs/wallet/initializer.js +41 -0
- package/dist/cjs/wallet/initializer.js.map +7 -0
- package/dist/cjs/wallet/register.d.ts +7 -0
- package/dist/cjs/wallet/register.js +67 -0
- package/dist/cjs/wallet/register.js.map +7 -0
- package/dist/cjs/wallet/state.d.ts +12 -37
- package/dist/cjs/wallet/state.js +79 -198
- package/dist/cjs/wallet/state.js.map +2 -2
- package/dist/cjs/wallet/types.d.ts +61 -22
- package/dist/cjs/wallet/types.js.map +1 -1
- package/dist/cjs/wallet/utils.d.ts +1 -1
- package/dist/cjs/wallet/utils.js.map +1 -1
- package/dist/cjs/wallet/{index.d.ts → wallet.d.ts} +3 -21
- package/dist/cjs/wallet/wallet.js +424 -0
- package/dist/cjs/wallet/wallet.js.map +7 -0
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/wallet/initializer.d.ts +11 -0
- package/dist/esm/wallet/initializer.js +21 -0
- package/dist/esm/wallet/initializer.js.map +7 -0
- package/dist/esm/wallet/register.d.ts +7 -0
- package/dist/esm/wallet/register.js +47 -0
- package/dist/esm/wallet/register.js.map +7 -0
- package/dist/esm/wallet/state.d.ts +12 -37
- package/dist/esm/wallet/state.js +81 -200
- package/dist/esm/wallet/state.js.map +2 -2
- package/dist/esm/wallet/types.d.ts +61 -22
- package/dist/esm/wallet/utils.d.ts +1 -1
- package/dist/esm/wallet/utils.js.map +1 -1
- package/dist/esm/wallet/{index.d.ts → wallet.d.ts} +3 -21
- package/dist/esm/wallet/wallet.js +402 -0
- package/dist/esm/wallet/wallet.js.map +7 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/cjs/wallet/index.js +0 -342
- package/dist/cjs/wallet/index.js.map +0 -7
- package/dist/esm/wallet/index.js +0 -321
- package/dist/esm/wallet/index.js.map +0 -7
package/CHANGELOG.md
CHANGED
package/dist/cjs/index.d.ts
CHANGED
|
@@ -4,7 +4,9 @@ export { EnokiFlow, type EnokiFlowConfig } from './EnokiFlow.js';
|
|
|
4
4
|
export { createLocalStorage, createSessionStorage, createInMemoryStorage, type SyncStore, } from './stores.js';
|
|
5
5
|
export { createDefaultEncryption, type Encryption } from './encryption.js';
|
|
6
6
|
export { EnokiKeypair, EnokiPublicKey } from './EnokiKeypair.js';
|
|
7
|
-
export {
|
|
7
|
+
export type { EnokiWallet } from './wallet/wallet.js';
|
|
8
|
+
export { registerEnokiWallets } from './wallet/register.js';
|
|
9
|
+
export { enokiWalletsInitializer } from './wallet/initializer.js';
|
|
8
10
|
export { isEnokiWallet, isGoogleWallet, isTwitchWallet, isFacebookWallet, getWalletMetadata, } from './wallet/utils.js';
|
|
9
11
|
export { type RegisterEnokiWalletsOptions } from './wallet/types.js';
|
|
10
12
|
export { isEnokiNetwork } from './utils.js';
|
package/dist/cjs/index.js
CHANGED
|
@@ -27,13 +27,14 @@ __export(index_exports, {
|
|
|
27
27
|
createInMemoryStorage: () => import_stores.createInMemoryStorage,
|
|
28
28
|
createLocalStorage: () => import_stores.createLocalStorage,
|
|
29
29
|
createSessionStorage: () => import_stores.createSessionStorage,
|
|
30
|
+
enokiWalletsInitializer: () => import_initializer.enokiWalletsInitializer,
|
|
30
31
|
getWalletMetadata: () => import_utils.getWalletMetadata,
|
|
31
32
|
isEnokiNetwork: () => import_utils2.isEnokiNetwork,
|
|
32
33
|
isEnokiWallet: () => import_utils.isEnokiWallet,
|
|
33
34
|
isFacebookWallet: () => import_utils.isFacebookWallet,
|
|
34
35
|
isGoogleWallet: () => import_utils.isGoogleWallet,
|
|
35
36
|
isTwitchWallet: () => import_utils.isTwitchWallet,
|
|
36
|
-
registerEnokiWallets: () =>
|
|
37
|
+
registerEnokiWallets: () => import_register.registerEnokiWallets
|
|
37
38
|
});
|
|
38
39
|
module.exports = __toCommonJS(index_exports);
|
|
39
40
|
var import_EnokiClient = require("./EnokiClient/index.js");
|
|
@@ -41,7 +42,8 @@ var import_EnokiFlow = require("./EnokiFlow.js");
|
|
|
41
42
|
var import_stores = require("./stores.js");
|
|
42
43
|
var import_encryption = require("./encryption.js");
|
|
43
44
|
var import_EnokiKeypair = require("./EnokiKeypair.js");
|
|
44
|
-
var
|
|
45
|
+
var import_register = require("./wallet/register.js");
|
|
46
|
+
var import_initializer = require("./wallet/initializer.js");
|
|
45
47
|
var import_utils = require("./wallet/utils.js");
|
|
46
48
|
var import_utils2 = require("./utils.js");
|
|
47
49
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport { EnokiClient, type EnokiClientConfig, EnokiClientError } from './EnokiClient/index.js';\nexport type { EnokiNetwork, AuthProvider } from './EnokiClient/type.js';\nexport { EnokiFlow, type EnokiFlowConfig } from './EnokiFlow.js';\nexport {\n\tcreateLocalStorage,\n\tcreateSessionStorage,\n\tcreateInMemoryStorage,\n\ttype SyncStore,\n} from './stores.js';\nexport { createDefaultEncryption, type Encryption } from './encryption.js';\nexport { EnokiKeypair, EnokiPublicKey } from './EnokiKeypair.js';\n\nexport { registerEnokiWallets
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yBAAsE;AAEtE,uBAAgD;AAChD,oBAKO;AACP,wBAAyD;AACzD,0BAA6C;
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport { EnokiClient, type EnokiClientConfig, EnokiClientError } from './EnokiClient/index.js';\nexport type { EnokiNetwork, AuthProvider } from './EnokiClient/type.js';\nexport { EnokiFlow, type EnokiFlowConfig } from './EnokiFlow.js';\nexport {\n\tcreateLocalStorage,\n\tcreateSessionStorage,\n\tcreateInMemoryStorage,\n\ttype SyncStore,\n} from './stores.js';\nexport { createDefaultEncryption, type Encryption } from './encryption.js';\nexport { EnokiKeypair, EnokiPublicKey } from './EnokiKeypair.js';\n\nexport type { EnokiWallet } from './wallet/wallet.js';\nexport { registerEnokiWallets } from './wallet/register.js';\nexport { enokiWalletsInitializer } from './wallet/initializer.js';\n\nexport {\n\tisEnokiWallet,\n\tisGoogleWallet,\n\tisTwitchWallet,\n\tisFacebookWallet,\n\tgetWalletMetadata,\n} from './wallet/utils.js';\nexport { type RegisterEnokiWalletsOptions } from './wallet/types.js';\n\nexport { isEnokiNetwork } from './utils.js';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yBAAsE;AAEtE,uBAAgD;AAChD,oBAKO;AACP,wBAAyD;AACzD,0BAA6C;AAG7C,sBAAqC;AACrC,yBAAwC;AAExC,mBAMO;AAGP,IAAAA,gBAA+B;",
|
|
6
6
|
"names": ["import_utils"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ClientWithCoreApi, Experimental_SuiClientTypes } from '@mysten/sui/experimental';
|
|
2
|
+
import type { RegisterEnokiWalletsOptions } from './types.js';
|
|
3
|
+
export declare function enokiWalletsInitializer(options: Omit<RegisterEnokiWalletsOptions, 'clients' | 'getCurrentNetwork'>): {
|
|
4
|
+
id: string;
|
|
5
|
+
initialize({ networks, getClient, }: {
|
|
6
|
+
networks: readonly Experimental_SuiClientTypes.Network[];
|
|
7
|
+
getClient: (network?: Experimental_SuiClientTypes.Network) => ClientWithCoreApi;
|
|
8
|
+
}): Promise<{
|
|
9
|
+
unregister: () => void;
|
|
10
|
+
}>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var initializer_exports = {};
|
|
20
|
+
__export(initializer_exports, {
|
|
21
|
+
enokiWalletsInitializer: () => enokiWalletsInitializer
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(initializer_exports);
|
|
24
|
+
var import_register = require("./register.js");
|
|
25
|
+
function enokiWalletsInitializer(options) {
|
|
26
|
+
return {
|
|
27
|
+
id: "enoki-wallets-initializer",
|
|
28
|
+
async initialize({
|
|
29
|
+
networks,
|
|
30
|
+
getClient
|
|
31
|
+
}) {
|
|
32
|
+
const { unregister } = (0, import_register.registerEnokiWallets)({
|
|
33
|
+
...options,
|
|
34
|
+
getCurrentNetwork: () => getClient().network,
|
|
35
|
+
clients: networks.map(getClient)
|
|
36
|
+
});
|
|
37
|
+
return { unregister };
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=initializer.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/wallet/initializer.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { ClientWithCoreApi, Experimental_SuiClientTypes } from '@mysten/sui/experimental';\nimport { registerEnokiWallets } from './register.js';\nimport type { RegisterEnokiWalletsOptions } from './types.js';\n\nexport function enokiWalletsInitializer(\n\toptions: Omit<RegisterEnokiWalletsOptions, 'clients' | 'getCurrentNetwork'>,\n) {\n\treturn {\n\t\tid: 'enoki-wallets-initializer',\n\t\tasync initialize({\n\t\t\tnetworks,\n\t\t\tgetClient,\n\t\t}: {\n\t\t\tnetworks: readonly Experimental_SuiClientTypes.Network[];\n\t\t\tgetClient: (network?: Experimental_SuiClientTypes.Network) => ClientWithCoreApi;\n\t\t}) {\n\t\t\tconst { unregister } = registerEnokiWallets({\n\t\t\t\t...options,\n\t\t\t\tgetCurrentNetwork: () => getClient().network,\n\t\t\t\tclients: networks.map(getClient),\n\t\t\t});\n\n\t\t\treturn { unregister };\n\t\t},\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,sBAAqC;AAG9B,SAAS,wBACf,SACC;AACD,SAAO;AAAA,IACN,IAAI;AAAA,IACJ,MAAM,WAAW;AAAA,MAChB;AAAA,MACA;AAAA,IACD,GAGG;AACF,YAAM,EAAE,WAAW,QAAI,sCAAqB;AAAA,QAC3C,GAAG;AAAA,QACH,mBAAmB,MAAM,UAAU,EAAE;AAAA,QACrC,SAAS,SAAS,IAAI,SAAS;AAAA,MAChC,CAAC;AAED,aAAO,EAAE,WAAW;AAAA,IACrB;AAAA,EACD;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { EnokiWallet } from './wallet.js';
|
|
2
|
+
import type { RegisterEnokiWalletsOptions } from './types.js';
|
|
3
|
+
import type { AuthProvider } from '../EnokiClient/type.js';
|
|
4
|
+
export declare function registerEnokiWallets({ providers, windowFeatures, ...config }: RegisterEnokiWalletsOptions): {
|
|
5
|
+
wallets: Partial<Record<AuthProvider, EnokiWallet>>;
|
|
6
|
+
unregister: () => void;
|
|
7
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var register_exports = {};
|
|
20
|
+
__export(register_exports, {
|
|
21
|
+
registerEnokiWallets: () => registerEnokiWallets
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(register_exports);
|
|
24
|
+
var import_wallet = require("./wallet.js");
|
|
25
|
+
var import_wallet_standard = require("@mysten/wallet-standard");
|
|
26
|
+
var import_utils = require("../utils.js");
|
|
27
|
+
var import_providers = require("./providers.js");
|
|
28
|
+
function registerEnokiWallets({
|
|
29
|
+
providers,
|
|
30
|
+
windowFeatures = defaultWindowFeatures,
|
|
31
|
+
...config
|
|
32
|
+
}) {
|
|
33
|
+
const clients = "clients" in config ? config.clients : [Object.assign(config.client, { network: config.network ?? "mainnet" })];
|
|
34
|
+
const enokiCompatibleClients = clients.filter(({ network }) => (0, import_utils.isEnokiNetwork)(network));
|
|
35
|
+
if (enokiCompatibleClients.length === 0) {
|
|
36
|
+
throw new Error("None of the specified clients are compatible with Enoki.");
|
|
37
|
+
}
|
|
38
|
+
const getCurrentNetwork = "clients" in config ? config.getCurrentNetwork : () => clients[0].network;
|
|
39
|
+
const walletsApi = (0, import_wallet_standard.getWallets)();
|
|
40
|
+
const wallets = {};
|
|
41
|
+
for (const { name, icon, provider } of import_providers.ENOKI_PROVIDER_WALLETS_INFO) {
|
|
42
|
+
const providerOptions = providers[provider];
|
|
43
|
+
if (providerOptions) {
|
|
44
|
+
wallets[provider] = new import_wallet.EnokiWallet({
|
|
45
|
+
...providerOptions,
|
|
46
|
+
name,
|
|
47
|
+
icon,
|
|
48
|
+
provider,
|
|
49
|
+
windowFeatures,
|
|
50
|
+
getCurrentNetwork,
|
|
51
|
+
apiKey: config.apiKey,
|
|
52
|
+
apiUrl: config.apiUrl,
|
|
53
|
+
clients: enokiCompatibleClients
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const unregister = walletsApi.register(...Object.values(wallets));
|
|
58
|
+
return { wallets, unregister };
|
|
59
|
+
}
|
|
60
|
+
function defaultWindowFeatures() {
|
|
61
|
+
const width = 500;
|
|
62
|
+
const height = 800;
|
|
63
|
+
const left = (screen.width - width) / 2;
|
|
64
|
+
const top = (screen.height - height) / 4;
|
|
65
|
+
return `popup=1;toolbar=0;status=0;resizable=1,width=${width},height=${height},top=${top},left=${left}`;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/wallet/register.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { EnokiWallet } from './wallet.js';\nimport type { RegisterEnokiWalletsOptions } from './types.js';\nimport { getWallets } from '@mysten/wallet-standard';\nimport type { ClientWithCoreApi } from '@mysten/sui/experimental';\nimport type { AuthProvider } from '../EnokiClient/type.js';\nimport { isEnokiNetwork } from '../utils.js';\nimport { ENOKI_PROVIDER_WALLETS_INFO } from './providers.js';\n\nexport function registerEnokiWallets({\n\tproviders,\n\twindowFeatures = defaultWindowFeatures,\n\t...config\n}: RegisterEnokiWalletsOptions) {\n\tconst clients: ClientWithCoreApi[] =\n\t\t'clients' in config\n\t\t\t? config.clients\n\t\t\t: [Object.assign(config.client, { network: config.network ?? 'mainnet' })];\n\n\tconst enokiCompatibleClients = clients.filter(({ network }) => isEnokiNetwork(network));\n\tif (enokiCompatibleClients.length === 0) {\n\t\tthrow new Error('None of the specified clients are compatible with Enoki.');\n\t}\n\n\tconst getCurrentNetwork =\n\t\t'clients' in config ? config.getCurrentNetwork : () => clients[0].network;\n\n\tconst walletsApi = getWallets();\n\tconst wallets: Partial<Record<AuthProvider, EnokiWallet>> = {};\n\n\tfor (const { name, icon, provider } of ENOKI_PROVIDER_WALLETS_INFO) {\n\t\tconst providerOptions = providers[provider];\n\t\tif (providerOptions) {\n\t\t\twallets[provider] = new EnokiWallet({\n\t\t\t\t...providerOptions,\n\t\t\t\tname,\n\t\t\t\ticon,\n\t\t\t\tprovider,\n\t\t\t\twindowFeatures,\n\t\t\t\tgetCurrentNetwork,\n\t\t\t\tapiKey: config.apiKey,\n\t\t\t\tapiUrl: config.apiUrl,\n\t\t\t\tclients: enokiCompatibleClients,\n\t\t\t});\n\t\t}\n\t}\n\n\tconst unregister = walletsApi.register(...Object.values(wallets));\n\treturn { wallets, unregister };\n}\n\nfunction defaultWindowFeatures() {\n\tconst width = 500;\n\tconst height = 800;\n\tconst left = (screen.width - width) / 2;\n\tconst top = (screen.height - height) / 4;\n\n\treturn `popup=1;toolbar=0;status=0;resizable=1,width=${width},height=${height},top=${top},left=${left}`;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA4B;AAE5B,6BAA2B;AAG3B,mBAA+B;AAC/B,uBAA4C;AAErC,SAAS,qBAAqB;AAAA,EACpC;AAAA,EACA,iBAAiB;AAAA,EACjB,GAAG;AACJ,GAAgC;AAC/B,QAAM,UACL,aAAa,SACV,OAAO,UACP,CAAC,OAAO,OAAO,OAAO,QAAQ,EAAE,SAAS,OAAO,WAAW,UAAU,CAAC,CAAC;AAE3E,QAAM,yBAAyB,QAAQ,OAAO,CAAC,EAAE,QAAQ,UAAM,6BAAe,OAAO,CAAC;AACtF,MAAI,uBAAuB,WAAW,GAAG;AACxC,UAAM,IAAI,MAAM,0DAA0D;AAAA,EAC3E;AAEA,QAAM,oBACL,aAAa,SAAS,OAAO,oBAAoB,MAAM,QAAQ,CAAC,EAAE;AAEnE,QAAM,iBAAa,mCAAW;AAC9B,QAAM,UAAsD,CAAC;AAE7D,aAAW,EAAE,MAAM,MAAM,SAAS,KAAK,8CAA6B;AACnE,UAAM,kBAAkB,UAAU,QAAQ;AAC1C,QAAI,iBAAiB;AACpB,cAAQ,QAAQ,IAAI,IAAI,0BAAY;AAAA,QACnC,GAAG;AAAA,QACH;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,QAAQ,OAAO;AAAA,QACf,QAAQ,OAAO;AAAA,QACf,SAAS;AAAA,MACV,CAAC;AAAA,IACF;AAAA,EACD;AAEA,QAAM,aAAa,WAAW,SAAS,GAAG,OAAO,OAAO,OAAO,CAAC;AAChE,SAAO,EAAE,SAAS,WAAW;AAC9B;AAEA,SAAS,wBAAwB;AAChC,QAAM,QAAQ;AACd,QAAM,SAAS;AACf,QAAM,QAAQ,OAAO,QAAQ,SAAS;AACtC,QAAM,OAAO,OAAO,SAAS,UAAU;AAEvC,SAAO,gDAAgD,KAAK,WAAW,MAAM,QAAQ,GAAG,SAAS,IAAI;AACtG;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,43 +1,18 @@
|
|
|
1
|
-
import type { ZkLoginSignatureInputs } from '@mysten/sui/zklogin';
|
|
2
1
|
import type { WritableAtom } from 'nanostores';
|
|
3
2
|
import type { EnokiClientConfig } from '../EnokiClient/index.js';
|
|
4
|
-
import type {
|
|
5
|
-
import {
|
|
6
|
-
type
|
|
7
|
-
|
|
3
|
+
import type { ClientWithCoreApi, Experimental_SuiClientTypes } from '@mysten/sui/experimental';
|
|
4
|
+
import type { EnokiSessionContext, ZkLoginSession, ZkLoginState } from './types.js';
|
|
5
|
+
export type EnokiWalletStateConfig = EnokiClientConfig & {
|
|
6
|
+
clients: ClientWithCoreApi[];
|
|
7
|
+
clientId: string;
|
|
8
8
|
};
|
|
9
|
-
|
|
10
|
-
provider?: AuthProvider;
|
|
11
|
-
address?: string;
|
|
12
|
-
salt?: string;
|
|
13
|
-
publicKey?: string;
|
|
14
|
-
}
|
|
15
|
-
interface ZkLoginSession {
|
|
16
|
-
maxEpoch: number;
|
|
17
|
-
randomness: string;
|
|
18
|
-
expiresAt: number;
|
|
19
|
-
jwt?: string;
|
|
20
|
-
proof?: ZkLoginSignatureInputs;
|
|
21
|
-
}
|
|
22
|
-
export declare class INTERNAL_ONLY_EnokiFlow {
|
|
9
|
+
export declare class EnokiWalletState {
|
|
23
10
|
#private;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
$zkLoginState: WritableAtom<ZkLoginState>;
|
|
29
|
-
constructor(config: EnokiFlowConfig);
|
|
30
|
-
get network(): EnokiNetwork;
|
|
31
|
-
createAuthorizationURL(input: {
|
|
32
|
-
provider: AuthProvider;
|
|
33
|
-
clientId: string;
|
|
34
|
-
redirectUrl: string;
|
|
35
|
-
extraParams?: Record<string, string>;
|
|
36
|
-
}): Promise<string>;
|
|
37
|
-
handleAuthCallback(hash?: string): Promise<string | null>;
|
|
38
|
-
getSession(): Promise<ZkLoginSession | null>;
|
|
11
|
+
constructor(config: EnokiWalletStateConfig);
|
|
12
|
+
get zkLoginState(): WritableAtom<ZkLoginState>;
|
|
13
|
+
get sessionContextByNetwork(): Map<Experimental_SuiClientTypes.Network, EnokiSessionContext>;
|
|
14
|
+
getSessionContext(network: Experimental_SuiClientTypes.Network): EnokiSessionContext;
|
|
39
15
|
logout(): Promise<void>;
|
|
40
|
-
|
|
41
|
-
|
|
16
|
+
setSession(state: EnokiSessionContext, newValue: ZkLoginSession | null): Promise<void>;
|
|
17
|
+
getSession({ $zkLoginSession, storageKey }: EnokiSessionContext): Promise<ZkLoginSession | null>;
|
|
42
18
|
}
|
|
43
|
-
export {};
|
package/dist/cjs/wallet/state.js
CHANGED
|
@@ -26,140 +26,83 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
|
|
|
26
26
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
27
27
|
var state_exports = {};
|
|
28
28
|
__export(state_exports, {
|
|
29
|
-
|
|
29
|
+
EnokiWalletState: () => EnokiWalletState
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(state_exports);
|
|
32
|
-
var import_webcrypto = require("@mysten/signers/webcrypto");
|
|
33
|
-
var import_zklogin = require("@mysten/sui/zklogin");
|
|
34
32
|
var import_idb_keyval = require("idb-keyval");
|
|
35
33
|
var import_nanostores = require("nanostores");
|
|
36
34
|
var import_encryption = require("../encryption.js");
|
|
37
|
-
var import_EnokiClient = require("../EnokiClient/index.js");
|
|
38
|
-
var import_EnokiKeypair = require("../EnokiKeypair.js");
|
|
39
35
|
var import_stores = require("../stores.js");
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
STATE: `@enoki/flow/state/${apiKey}/${network}`,
|
|
43
|
-
SESSION: `@enoki/flow/session/${apiKey}/${network}`
|
|
44
|
-
});
|
|
45
|
-
class INTERNAL_ONLY_EnokiFlow {
|
|
36
|
+
var _encryption, _encryptionKey, _sessionStore, _stateStorageKey, _sessionContextByNetwork, _zkLoginState, _EnokiWalletState_instances, createZkLoginState_fn;
|
|
37
|
+
class EnokiWalletState {
|
|
46
38
|
constructor(config) {
|
|
47
|
-
__privateAdd(this,
|
|
48
|
-
__privateAdd(this, _storageKeys);
|
|
49
|
-
__privateAdd(this, _enokiClient);
|
|
50
|
-
__privateAdd(this, _network);
|
|
39
|
+
__privateAdd(this, _EnokiWalletState_instances);
|
|
51
40
|
__privateAdd(this, _encryption);
|
|
52
41
|
__privateAdd(this, _encryptionKey);
|
|
53
|
-
__privateAdd(this,
|
|
54
|
-
__privateAdd(this,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
apiUrl: config.apiUrl
|
|
58
|
-
}));
|
|
59
|
-
__privateSet(this, _network, config.network);
|
|
42
|
+
__privateAdd(this, _sessionStore);
|
|
43
|
+
__privateAdd(this, _stateStorageKey);
|
|
44
|
+
__privateAdd(this, _sessionContextByNetwork);
|
|
45
|
+
__privateAdd(this, _zkLoginState);
|
|
60
46
|
__privateSet(this, _encryptionKey, config.apiKey);
|
|
61
47
|
__privateSet(this, _encryption, (0, import_encryption.createDefaultEncryption)());
|
|
62
|
-
__privateSet(this,
|
|
63
|
-
__privateSet(this,
|
|
64
|
-
__privateSet(this,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
});
|
|
48
|
+
__privateSet(this, _sessionStore, (0, import_stores.createSessionStorage)());
|
|
49
|
+
__privateSet(this, _stateStorageKey, `@enoki/flow/state/${config.apiKey}/${config.clientId}`);
|
|
50
|
+
__privateSet(this, _zkLoginState, __privateMethod(this, _EnokiWalletState_instances, createZkLoginState_fn).call(this));
|
|
51
|
+
__privateSet(this, _sessionContextByNetwork, config.clients.reduce((accumulator, client) => {
|
|
52
|
+
const network = client.network;
|
|
53
|
+
const storageKey = `@enoki/flow/session/${config.apiKey}/${network}/${config.clientId}`;
|
|
54
|
+
const idbStore = (0, import_idb_keyval.createStore)(`${config.apiKey}_${network}_${config.clientId}`, "enoki");
|
|
55
|
+
const sessionContext = {
|
|
56
|
+
$zkLoginSession: (0, import_nanostores.atom)({ initialized: false, value: null }),
|
|
57
|
+
client,
|
|
58
|
+
storageKey,
|
|
59
|
+
idbStore
|
|
60
|
+
};
|
|
61
|
+
(0, import_nanostores.onMount)(sessionContext.$zkLoginSession, () => {
|
|
62
|
+
this.getSession(sessionContext);
|
|
63
|
+
});
|
|
64
|
+
return accumulator.set(network, sessionContext);
|
|
65
|
+
}, /* @__PURE__ */ new Map()));
|
|
81
66
|
}
|
|
82
|
-
get
|
|
83
|
-
return __privateGet(this,
|
|
67
|
+
get zkLoginState() {
|
|
68
|
+
return __privateGet(this, _zkLoginState);
|
|
84
69
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
...input.extraParams,
|
|
93
|
-
nonce,
|
|
94
|
-
client_id: input.clientId,
|
|
95
|
-
redirect_uri: input.redirectUrl,
|
|
96
|
-
response_type: "id_token",
|
|
97
|
-
// TODO: Eventually fetch the scopes for this client ID from the Enoki service:
|
|
98
|
-
scope: [
|
|
99
|
-
"openid",
|
|
100
|
-
// Merge the requested scopes in with the required openid scopes:
|
|
101
|
-
...input.extraParams?.scope ? input.extraParams.scope.split(" ") : []
|
|
102
|
-
].filter(Boolean).join(" ")
|
|
103
|
-
});
|
|
104
|
-
let oauthUrl;
|
|
105
|
-
switch (input.provider) {
|
|
106
|
-
case "google": {
|
|
107
|
-
oauthUrl = `https://accounts.google.com/o/oauth2/v2/auth?${params}`;
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
case "facebook": {
|
|
111
|
-
oauthUrl = `https://www.facebook.com/v17.0/dialog/oauth?${params}`;
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
case "twitch": {
|
|
115
|
-
params.set("force_verify", "true");
|
|
116
|
-
oauthUrl = `https://id.twitch.tv/oauth2/authorize?${params}`;
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
default:
|
|
120
|
-
throw new Error(`Invalid provider: ${input.provider}`);
|
|
70
|
+
get sessionContextByNetwork() {
|
|
71
|
+
return __privateGet(this, _sessionContextByNetwork);
|
|
72
|
+
}
|
|
73
|
+
getSessionContext(network) {
|
|
74
|
+
const context = __privateGet(this, _sessionContextByNetwork).get(network);
|
|
75
|
+
if (!context) {
|
|
76
|
+
throw new Error(`The network ${network} isn't supported.`);
|
|
121
77
|
}
|
|
122
|
-
|
|
123
|
-
await (0, import_idb_keyval.set)("ephemeralKeyPair", ephemeralKeyPair.export(), __privateGet(this, _idbStore));
|
|
124
|
-
await __privateMethod(this, _INTERNAL_ONLY_EnokiFlow_instances, setSession_fn).call(this, {
|
|
125
|
-
expiresAt: estimatedExpiration,
|
|
126
|
-
maxEpoch,
|
|
127
|
-
randomness
|
|
128
|
-
});
|
|
129
|
-
return oauthUrl;
|
|
78
|
+
return context;
|
|
130
79
|
}
|
|
131
|
-
async
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
);
|
|
80
|
+
async logout() {
|
|
81
|
+
__privateGet(this, _zkLoginState).set({});
|
|
82
|
+
__privateGet(this, _sessionStore).delete(__privateGet(this, _stateStorageKey));
|
|
83
|
+
for (const state of __privateGet(this, _sessionContextByNetwork).values()) {
|
|
84
|
+
await (0, import_idb_keyval.clear)(state.idbStore);
|
|
85
|
+
await this.setSession(state, null);
|
|
138
86
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
87
|
+
}
|
|
88
|
+
async setSession(state, newValue) {
|
|
89
|
+
if (newValue) {
|
|
90
|
+
const storedValue = await __privateGet(this, _encryption).encrypt(
|
|
91
|
+
__privateGet(this, _encryptionKey),
|
|
92
|
+
JSON.stringify(newValue)
|
|
93
|
+
);
|
|
94
|
+
__privateGet(this, _sessionStore).set(state.storageKey, storedValue);
|
|
95
|
+
} else {
|
|
96
|
+
__privateGet(this, _sessionStore).delete(state.storageKey);
|
|
142
97
|
}
|
|
143
|
-
(
|
|
144
|
-
const { address, salt, publicKey } = await __privateGet(this, _enokiClient).getZkLogin({ jwt });
|
|
145
|
-
this.$zkLoginState.set({
|
|
146
|
-
...this.$zkLoginState.get(),
|
|
147
|
-
salt,
|
|
148
|
-
address,
|
|
149
|
-
publicKey
|
|
150
|
-
});
|
|
151
|
-
await __privateMethod(this, _INTERNAL_ONLY_EnokiFlow_instances, setSession_fn).call(this, {
|
|
152
|
-
...zkp,
|
|
153
|
-
jwt
|
|
154
|
-
});
|
|
155
|
-
return params.get("state");
|
|
98
|
+
state.$zkLoginSession.set({ initialized: true, value: newValue });
|
|
156
99
|
}
|
|
157
|
-
async getSession() {
|
|
158
|
-
if (
|
|
159
|
-
return
|
|
100
|
+
async getSession({ $zkLoginSession, storageKey }) {
|
|
101
|
+
if ($zkLoginSession.get().initialized) {
|
|
102
|
+
return $zkLoginSession.get().value;
|
|
160
103
|
}
|
|
161
104
|
try {
|
|
162
|
-
const storedValue = __privateGet(this,
|
|
105
|
+
const storedValue = __privateGet(this, _sessionStore).get(storageKey);
|
|
163
106
|
if (!storedValue) return null;
|
|
164
107
|
const state = JSON.parse(
|
|
165
108
|
await __privateGet(this, _encryption).decrypt(__privateGet(this, _encryptionKey), storedValue)
|
|
@@ -167,97 +110,35 @@ class INTERNAL_ONLY_EnokiFlow {
|
|
|
167
110
|
if (state?.expiresAt && Date.now() > state.expiresAt) {
|
|
168
111
|
await this.logout();
|
|
169
112
|
} else {
|
|
170
|
-
|
|
113
|
+
$zkLoginSession.set({ initialized: true, value: state });
|
|
171
114
|
}
|
|
172
115
|
} catch {
|
|
173
|
-
|
|
116
|
+
$zkLoginSession.set({ initialized: true, value: null });
|
|
174
117
|
}
|
|
175
|
-
return
|
|
176
|
-
}
|
|
177
|
-
async logout() {
|
|
178
|
-
this.$zkLoginState.set({});
|
|
179
|
-
__privateGet(this, _store).delete(__privateGet(this, _storageKeys).STATE);
|
|
180
|
-
await (0, import_idb_keyval.clear)(__privateGet(this, _idbStore));
|
|
181
|
-
await __privateMethod(this, _INTERNAL_ONLY_EnokiFlow_instances, setSession_fn).call(this, null);
|
|
182
|
-
}
|
|
183
|
-
// TODO: Should this return the proof if it already exists?
|
|
184
|
-
async getProof() {
|
|
185
|
-
const zkp = await this.getSession();
|
|
186
|
-
const { salt } = this.$zkLoginState.get();
|
|
187
|
-
if (zkp?.proof) {
|
|
188
|
-
if (zkp.expiresAt && Date.now() > zkp.expiresAt) {
|
|
189
|
-
throw new Error("Stored proof is expired.");
|
|
190
|
-
}
|
|
191
|
-
return zkp.proof;
|
|
192
|
-
}
|
|
193
|
-
if (!salt || !zkp || !zkp.jwt) {
|
|
194
|
-
throw new Error("Missing required parameters for proof generation");
|
|
195
|
-
}
|
|
196
|
-
const storedNativeSigner = await (0, import_idb_keyval.get)(
|
|
197
|
-
"ephemeralKeyPair",
|
|
198
|
-
__privateGet(this, _idbStore)
|
|
199
|
-
);
|
|
200
|
-
if (!storedNativeSigner) {
|
|
201
|
-
throw new Error("Native signer not found in store.");
|
|
202
|
-
}
|
|
203
|
-
const ephemeralKeyPair = import_webcrypto.WebCryptoSigner.import(storedNativeSigner);
|
|
204
|
-
const proof = await __privateGet(this, _enokiClient).createZkLoginZkp({
|
|
205
|
-
network: __privateGet(this, _network),
|
|
206
|
-
jwt: zkp.jwt,
|
|
207
|
-
maxEpoch: zkp.maxEpoch,
|
|
208
|
-
randomness: zkp.randomness,
|
|
209
|
-
ephemeralPublicKey: ephemeralKeyPair.getPublicKey()
|
|
210
|
-
});
|
|
211
|
-
await __privateMethod(this, _INTERNAL_ONLY_EnokiFlow_instances, setSession_fn).call(this, {
|
|
212
|
-
...zkp,
|
|
213
|
-
proof
|
|
214
|
-
});
|
|
215
|
-
return proof;
|
|
216
|
-
}
|
|
217
|
-
async getKeypair() {
|
|
218
|
-
await this.getProof();
|
|
219
|
-
const zkp = await this.getSession();
|
|
220
|
-
const { address } = this.$zkLoginState.get();
|
|
221
|
-
if (!address || !zkp || !zkp.proof) {
|
|
222
|
-
throw new Error("Missing required data for keypair generation.");
|
|
223
|
-
}
|
|
224
|
-
if (Date.now() > zkp.expiresAt) {
|
|
225
|
-
throw new Error("Stored proof is expired.");
|
|
226
|
-
}
|
|
227
|
-
const storedNativeSigner = await (0, import_idb_keyval.get)(
|
|
228
|
-
"ephemeralKeyPair",
|
|
229
|
-
__privateGet(this, _idbStore)
|
|
230
|
-
);
|
|
231
|
-
if (!storedNativeSigner) {
|
|
232
|
-
throw new Error("Native signer not found in store.");
|
|
233
|
-
}
|
|
234
|
-
const ephemeralKeypair = import_webcrypto.WebCryptoSigner.import(storedNativeSigner);
|
|
235
|
-
return new import_EnokiKeypair.EnokiKeypair({
|
|
236
|
-
address,
|
|
237
|
-
ephemeralKeypair,
|
|
238
|
-
maxEpoch: zkp.maxEpoch,
|
|
239
|
-
proof: zkp.proof
|
|
240
|
-
});
|
|
118
|
+
return $zkLoginSession.get().value;
|
|
241
119
|
}
|
|
242
120
|
}
|
|
243
|
-
_storageKeys = new WeakMap();
|
|
244
|
-
_enokiClient = new WeakMap();
|
|
245
|
-
_network = new WeakMap();
|
|
246
121
|
_encryption = new WeakMap();
|
|
247
122
|
_encryptionKey = new WeakMap();
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
123
|
+
_sessionStore = new WeakMap();
|
|
124
|
+
_stateStorageKey = new WeakMap();
|
|
125
|
+
_sessionContextByNetwork = new WeakMap();
|
|
126
|
+
_zkLoginState = new WeakMap();
|
|
127
|
+
_EnokiWalletState_instances = new WeakSet();
|
|
128
|
+
createZkLoginState_fn = function() {
|
|
129
|
+
const storage = (0, import_stores.createLocalStorage)();
|
|
130
|
+
let storedState = null;
|
|
131
|
+
try {
|
|
132
|
+
const rawStoredValue = storage.get(__privateGet(this, _stateStorageKey));
|
|
133
|
+
if (rawStoredValue) {
|
|
134
|
+
storedState = JSON.parse(rawStoredValue);
|
|
135
|
+
}
|
|
136
|
+
} catch {
|
|
260
137
|
}
|
|
261
|
-
|
|
138
|
+
const $zkLoginState = (0, import_nanostores.atom)(storedState || {});
|
|
139
|
+
(0, import_nanostores.onSet)($zkLoginState, ({ newValue }) => {
|
|
140
|
+
storage.set(__privateGet(this, _stateStorageKey), JSON.stringify(newValue));
|
|
141
|
+
});
|
|
142
|
+
return $zkLoginState;
|
|
262
143
|
};
|
|
263
144
|
//# sourceMappingURL=state.js.map
|