@openfort/openfort-js 0.4.6 → 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.
Files changed (51) hide show
  1. package/README.md +28 -59
  2. package/dist/{utils → clients}/iframe-client.d.ts +2 -1
  3. package/dist/{utils → clients}/iframe-client.js +39 -10
  4. package/dist/clients/iframe-client.js.map +1 -0
  5. package/dist/{key-pair.d.ts → crypto/key-pair.d.ts} +3 -11
  6. package/dist/{key-pair.js → crypto/key-pair.js} +5 -18
  7. package/dist/crypto/key-pair.js.map +1 -0
  8. package/dist/generated/api.d.ts +160 -67
  9. package/dist/generated/api.js +251 -116
  10. package/dist/generated/api.js.map +1 -1
  11. package/dist/index.d.ts +2 -5
  12. package/dist/index.js +4 -5
  13. package/dist/index.js.map +1 -1
  14. package/dist/openfort.d.ts +27 -8
  15. package/dist/openfort.js +153 -18
  16. package/dist/openfort.js.map +1 -1
  17. package/dist/openfortAuth.d.ts +15 -2
  18. package/dist/openfortAuth.js +50 -4
  19. package/dist/openfortAuth.js.map +1 -1
  20. package/dist/recovery/passwordRecovery.d.ts +6 -0
  21. package/dist/recovery/passwordRecovery.js +13 -0
  22. package/dist/recovery/passwordRecovery.js.map +1 -0
  23. package/dist/recovery/recovery.d.ts +3 -0
  24. package/dist/{storage/base-storage.js → recovery/recovery.js} +1 -1
  25. package/dist/recovery/recovery.js.map +1 -0
  26. package/dist/signer/embedded.signer.d.ts +20 -6
  27. package/dist/signer/embedded.signer.js +42 -9
  28. package/dist/signer/embedded.signer.js.map +1 -1
  29. package/dist/signer/session.signer.d.ts +12 -4
  30. package/dist/signer/session.signer.js +35 -7
  31. package/dist/signer/session.signer.js.map +1 -1
  32. package/dist/signer/signer.d.ts +9 -1
  33. package/dist/signer/signer.js +6 -0
  34. package/dist/signer/signer.js.map +1 -1
  35. package/dist/storage/local-storage.d.ts +6 -13
  36. package/dist/storage/local-storage.js +9 -18
  37. package/dist/storage/local-storage.js.map +1 -1
  38. package/dist/storage/storage.d.ts +9 -0
  39. package/dist/storage/storage.js +8 -0
  40. package/dist/storage/storage.js.map +1 -0
  41. package/dist/version.d.ts +1 -1
  42. package/dist/version.js +1 -1
  43. package/package.json +1 -1
  44. package/tsconfig.tsbuildinfo +1 -1
  45. package/dist/key-pair.js.map +0 -1
  46. package/dist/storage/base-storage.d.ts +0 -6
  47. package/dist/storage/base-storage.js.map +0 -1
  48. package/dist/storage/storage-keys.d.ts +0 -4
  49. package/dist/storage/storage-keys.js +0 -9
  50. package/dist/storage/storage-keys.js.map +0 -1
  51. package/dist/utils/iframe-client.js.map +0 -1
package/README.md CHANGED
@@ -40,81 +40,50 @@ yarn add @openfort/openfort-js
40
40
 
41
41
  ## Usage
42
42
 
43
- The package needs to be configured with your account's public key, which is
44
- available in the [Openfort Dashboard][api-keys]. Require it with the key's
45
- value:
46
-
47
- ```js
48
- import Openfort from '@openfort/openfort-js';
49
- const openfort = new Openfort('pk_test_...');
50
- ```
51
- In order to sign messages, you have 4 options to choose from:
52
- * Let Openfort handle the signing process, dont need to pass any signer to the Openfort instance.
53
- * Sign yourself and pass the signature to Openfort, dont need to pass any signer to the Openfort instance.
54
- * Use a Session Key to sign messages, you need to pass a SessionSigner to the Openfort instance.
55
- * Use Embedded Signer to sign messages, you need to pass an Embedded Signer to the Openfort instance.
56
-
57
- #### Session Signer
58
- ```ts
59
- const sessionSigner = new SessionSigner()
60
- const openfort = new Openfort('pk_test_...', sessionSigner);
61
- ```
62
-
63
- #### Embedded Signer
64
- For the embedded signer, if your player has an account you can pass it to the embedded signer to use it. If the account is not provided, the embedded signer will check if the localstorage has a device which is already registered, if not, it will create a new device and store it in the localstorage.
65
- For the recovery process, you can ask the user for a password to encrypt the recovery share.
66
-
67
- ```ts
68
- const embeddedSigner = new EmbeddedSigner('pk_test_...', 'acc_...', '********');
69
- const openfort = new Openfort('pk_test_...', embeddedSigner);
70
- ```
71
-
72
-
73
- ### Create and store a new player session key
74
-
75
- 1. Create a session key pair for the player:
76
-
43
+ With the Openfort Unity SDK, you can sign transaction intents using one of four methods or signers:
77
44
  ```typescript
78
- openfort.createSessionKey();
45
+ const sdk = new Openfort("pk_test_XXXXXXX");
79
46
  ```
80
47
 
81
- 2. Save the generated session key pair on device:
48
+ ### 1. Session Signer
49
+ The Session Signer allows you to use external signing keys, without needing to provide it every time. Here's how to use it:
82
50
 
51
+ - **Configure the Session Key**: Call `configureSessionKey()`. This method returns an Ethereum address and a boolean indicating whether you need to register the key from the backend.
83
52
  ```typescript
84
- openfort.saveSessionKey();
53
+ const sessionKey = sdk.configureSessionKey();
85
54
  ```
55
+ - **Register Key and Send Signature Session Request**: If `sessionKey.isRegistered` boolean is false, register the key from the backend. Refer to the documentation for [session management](https://www.openfort.xyz/docs/guides/accounts/sessions).
56
+ - **Send Signature Transaction Intent Request**: When calling sendSignatureTransactionIntentRequest, pass the transaction intent ID and the user operation hash. The session signer will handle the signing.
57
+
58
+ ### 2. External Sign
86
59
 
87
- 3. Authorize player with the game backend service and passing the address of the session key pair:
60
+ This method allows you to externally sign transaction intents without logging in or additional configurations:
88
61
 
62
+ - **Call SendSignatureTransactionIntentRequest**: Simply pass the transaction intent ID and the signature.
89
63
  ```typescript
90
- const address = openfort.sessionKey.address
91
- // API call to the game backend with the address to register it
64
+ const response = await sdk.sendSignatureTransactionIntentRequest("transactionIntentId", null, "signature");
92
65
  ```
93
66
 
94
- #### Register the session key using a non-custodial signer
95
-
96
- If the Openfort account is owned by an external signer, the owner must use it to sign and approve the registration of the session key. The hash containing the message to be signed appears in [next_actions][next-action] from the create session request.
97
-
67
+ ### 3. Embedded Signer
68
+ The Embedded Signer uses SSS to manage the private key on the client side. To learn more, visit our [security documentation](https://www.openfort.xyz/docs/security).
69
+ - **Login and Configure the Embedded Signer**: First, ensure the user is logged in, using `LoginWithEmailPassword`, `LoginWithOAuth` or if not registred `SignUpWithEmailPassword`. Then call `ConfigureEmbeddedSigner`. If a `MissingRecoveryMethod` exception is thrown, it indicates there's no share on the device and you have to call `ConfigureEmbeddedRecovery` to provide a recovery method.
98
70
  ```typescript
99
- // Sign the message with the signer
100
- await openfort.sendSignatureSessionRequest(
101
- session_id,
102
- signed_message
103
- );
71
+ try {
72
+ await sdk.loginWithEmailPassword("email", "password");
73
+ sdk.configureEmbeddedSigner(chainId);
74
+ } catch (e) {
75
+ if (e instanceof MissingRecoveryMethod) {
76
+ await sdk.configureEmbeddedSignerRecovery(new PasswordRecovery("password"));
77
+ }
78
+ }
104
79
  ```
105
-
106
- ### Use the session key to sign a message
107
-
108
- The hash containing the message to be signed appears in [next_actions][next-action] from the create transactionIntent request.
109
-
80
+ For now the only recovery method available is the `PasswordRecovery` method.
81
+ - **Send Signature Transaction Intent Request**: Similar to the session signer, pass the transaction intent ID and the user operation hash. The embedded signer reconstructs the key and signs the transaction.
110
82
  ```typescript
111
- await openfort.signMessage(message);
112
- await openfort.sendSignatureTransactionIntentRequest(
113
- transactionIntent_id,
114
- signed_message
115
- );
83
+ const response = await sdk.sendSignatureTransactionIntentRequest("transactionIntentId", "userOp");
116
84
  ```
117
85
 
86
+
118
87
  ## Usage examples
119
88
  - [Next.js application with non-custodial signer](https://github.com/openfort-xyz/samples/tree/main/rainbow-ssv-nextjs)
120
89
  - [Next.js application with custodial signer and social login](https://github.com/openfort-xyz/samples/tree/main/ssv-social-nextjs)
@@ -2,10 +2,11 @@ export declare class IframeClient {
2
2
  private readonly _iframe;
3
3
  private readonly _chainId;
4
4
  constructor(publishableKey: string, accessToken: string, chainId: number, iframeURL?: string);
5
+ isLoaded(): boolean;
5
6
  private waitForIframeLoad;
6
7
  createAccount(password?: string): Promise<string>;
7
8
  registerDevice(account: string, password?: string): Promise<string>;
8
9
  getCurrentDevice(): Promise<string | null>;
9
10
  sign(message: string): Promise<string>;
10
- dispose(): void;
11
+ dispose(): Promise<void>;
11
12
  }
@@ -6,22 +6,26 @@ class IframeClient {
6
6
  if (!document) {
7
7
  throw new Error("must be run in a browser");
8
8
  }
9
+ const actualIframeURL = document.getElementById("openfort-iframe");
10
+ if (actualIframeURL) {
11
+ this._iframe = actualIframeURL;
12
+ return;
13
+ }
9
14
  this._chainId = chainId;
10
15
  this._iframe = document.createElement("iframe");
11
16
  const baseURL = iframeURL || "https://iframe.openfort.xyz";
12
17
  this._iframe.src = baseURL + "/iframe?accessToken=" + accessToken + "&publishableKey=" + publishableKey;
13
18
  this._iframe.style.display = "none";
19
+ this._iframe.id = "openfort-iframe";
14
20
  document.body.appendChild(this._iframe);
15
21
  }
16
- waitForIframeLoad() {
17
- if (!this._iframe.contentWindow) {
18
- return new Promise((resolve) => {
19
- this._iframe.onload = () => {
20
- resolve();
21
- };
22
- });
22
+ isLoaded() {
23
+ return this._iframe.contentWindow !== null;
24
+ }
25
+ async waitForIframeLoad() {
26
+ while (!this.isLoaded()) {
27
+ await new Promise((resolve) => setTimeout(resolve, 100));
23
28
  }
24
- return Promise.resolve();
25
29
  }
26
30
  async createAccount(password) {
27
31
  await this.waitForIframeLoad();
@@ -131,8 +135,33 @@ class IframeClient {
131
135
  }, 1000);
132
136
  });
133
137
  }
134
- dispose() {
135
- document.body.removeChild(this._iframe);
138
+ async dispose() {
139
+ await this.waitForIframeLoad();
140
+ return new Promise((resolve, reject) => {
141
+ const handleMessage = (event) => {
142
+ if (event.data.action === "loggedOut") {
143
+ if (event.data.success) {
144
+ document.body.removeChild(this._iframe);
145
+ resolve();
146
+ }
147
+ else {
148
+ reject(new Error(event.data.error || "Dispose failed"));
149
+ }
150
+ window.removeEventListener("message", handleMessage);
151
+ }
152
+ };
153
+ window.addEventListener("message", handleMessage);
154
+ setTimeout(() => {
155
+ if (this._iframe.contentWindow) {
156
+ this._iframe.contentWindow.postMessage({
157
+ action: "logout",
158
+ }, "*");
159
+ }
160
+ else {
161
+ console.error("No iframe content window");
162
+ }
163
+ }, 1000);
164
+ });
136
165
  }
137
166
  }
138
167
  exports.IframeClient = IframeClient;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iframe-client.js","sourceR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oBACJ,OAAO,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;gBAC9C,CAAC;YACL,CAAC,EAAE,IAAI,CAAC,CAAC;QACb,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAvMD,oCAuMC"}
@@ -1,7 +1,6 @@
1
1
  import { SigningKey } from "@ethersproject/signing-key";
2
2
  import { Bytes, BytesLike } from "@ethersproject/bytes";
3
3
  export declare class KeyPair extends SigningKey {
4
- private static readonly storage;
5
4
  /**
6
5
  * Initialize keypair based on the private key, if it is provided or generate a brand new keypair.
7
6
  * @param privateKey Optional parameter to initialize private key from
@@ -12,20 +11,13 @@ export declare class KeyPair extends SigningKey {
12
11
  * @param message Message to sign
13
12
  */
14
13
  sign(message: Bytes | string): string;
15
- /**
16
- * Save to the storage initialized as a static property of the KeyPair class
17
- */
18
- save(): void;
19
- /**
20
- * Remove the keypair from the storage
21
- */
22
- remove(): void;
23
14
  /**
24
15
  * Load private key from the storage and generate keypair based on it.
25
16
  */
26
- static load(): KeyPair | null;
17
+ static load(privateKey: string): KeyPair | null;
27
18
  /**
28
19
  * Return the address for the keypair
29
20
  */
30
- get address(): string;
21
+ getPublicKey(): string;
22
+ getPrivateKey(): string;
31
23
  }
@@ -2,8 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.KeyPair = void 0;
4
4
  const secp256k1_1 = require("@noble/curves/secp256k1");
5
- const local_storage_1 = require("./storage/local-storage");
6
- const storage_keys_1 = require("./storage/storage-keys");
7
5
  const signing_key_1 = require("@ethersproject/signing-key");
8
6
  const bytes_1 = require("@ethersproject/bytes");
9
7
  const transactions_1 = require("@ethersproject/transactions");
@@ -23,32 +21,21 @@ class KeyPair extends signing_key_1.SigningKey {
23
21
  sign(message) {
24
22
  return (0, bytes_1.joinSignature)(this.signDigest((0, hash_1.hashMessage)((0, bytes_1.arrayify)(message))));
25
23
  }
26
- /**
27
- * Save to the storage initialized as a static property of the KeyPair class
28
- */
29
- save() {
30
- KeyPair.storage.save(storage_keys_1.StorageKeys.SESSION_KEY, this.privateKey);
31
- }
32
- /**
33
- * Remove the keypair from the storage
34
- */
35
- remove() {
36
- KeyPair.storage.remove(storage_keys_1.StorageKeys.SESSION_KEY);
37
- }
38
24
  /**
39
25
  * Load private key from the storage and generate keypair based on it.
40
26
  */
41
- static load() {
42
- const privateKey = KeyPair.storage.get(storage_keys_1.StorageKeys.SESSION_KEY);
27
+ static load(privateKey) {
43
28
  return privateKey ? new KeyPair((0, bytes_1.arrayify)(privateKey)) : null;
44
29
  }
45
30
  /**
46
31
  * Return the address for the keypair
47
32
  */
48
- get address() {
33
+ getPublicKey() {
49
34
  return (0, transactions_1.computeAddress)(this.privateKey);
50
35
  }
36
+ getPrivateKey() {
37
+ return this.privateKey;
38
+ }
51
39
  }
52
40
  exports.KeyPair = KeyPair;
53
- KeyPair.storage = new local_storage_1.LocalStorage();
54
41
  //# sourceMappingURL=key-pair.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key-pair.js","sourceRoot":"","sources":["../../src/crypto/key-pair.ts"],"names":[],"mappings":";;;AAAA,uDAAkD;AAClD,4DAAsD;AACtD,gDAA+E;AAC/E,8DAA2D;AAC3D,8CAAgD;AAEhD,MAAa,OAAQ,SAAQ,wBAAU;IACnC;;;OAGG;IACH,YAAmB,aAAwB,qBAAS,CAAC,KAAK,CAAC,gBAAgB,EAAE;QACzE,KAAK,CAAC,UAAU,CAAC,CAAC;IACtB,CAAC;IAED;;;OAGG;IACI,IAAI,CAAC,OAAuB;QAC/B,OAAO,IAAA,qBAAa,EAAC,IAAI,CAAC,UAAU,CAAC,IAAA,kBAAW,EAAC,IAAA,gBAAQ,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1E,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,IAAI,CAAC,UAAkB;QACjC,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,IAAA,gBAAQ,EAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACjE,CAAC;IAED;;OAEG;IACI,YAAY;QACf,OAAO,IAAA,6BAAc,EAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC3C,CAAC;IAEM,aAAa;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;CACJ;AAlCD,0BAkCC"}