@openfort/openfort-js 0.0.2 → 0.1.2
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/.prettierrc +3 -2
- package/dist/api.d.ts +172 -172
- package/dist/api.js +653 -379
- package/dist/api.js.map +1 -1
- package/dist/base.d.ts +2 -2
- package/dist/base.js +0 -1
- package/dist/base.js.map +1 -1
- package/dist/common.d.ts +1 -1
- package/dist/common.js +9 -11
- package/dist/common.js.map +1 -1
- package/dist/configuration.js +2 -2
- package/dist/configuration.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/key-pair.d.ts +7 -22
- package/dist/key-pair.js +10 -37
- package/dist/key-pair.js.map +1 -1
- package/dist/openfort.d.ts +18 -5
- package/dist/openfort.js +66 -8
- package/dist/openfort.js.map +1 -1
- package/dist/storage/base-storage.d.ts +4 -3
- package/dist/storage/file-storage.d.ts +5 -4
- package/dist/storage/file-storage.js +4 -4
- package/dist/storage/file-storage.js.map +1 -1
- package/dist/storage/local-storage.d.ts +6 -5
- package/dist/storage/local-storage.js +4 -4
- package/dist/storage/local-storage.js.map +1 -1
- package/dist/storage/storage-keys.d.ts +4 -0
- package/dist/storage/storage-keys.js +9 -0
- package/dist/storage/storage-keys.js.map +1 -0
- package/dist/utils/http-error-handler.d.ts +1 -0
- package/dist/utils/http-error-handler.js +31 -0
- package/dist/utils/http-error-handler.js.map +1 -0
- package/package.json +3 -1
- package/tsconfig.json +13 -14
- package/tsconfig.tsbuildinfo +1 -1
package/dist/key-pair.d.ts
CHANGED
|
@@ -1,35 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { BaseStorage } from "./storage/base-storage";
|
|
2
|
+
import { SigningKey } from "@ethersproject/signing-key";
|
|
3
|
+
import { BytesLike } from "@ethersproject/bytes";
|
|
4
|
+
import { Hexable } from "@ethersproject/bytes/src.ts";
|
|
5
|
+
export declare class KeyPair extends SigningKey {
|
|
5
6
|
private static readonly localStorage;
|
|
6
7
|
private static readonly fileStorage;
|
|
7
|
-
private static readonly storageKey;
|
|
8
|
-
private readonly publicKey;
|
|
9
8
|
/**
|
|
10
9
|
* Initialize keypair based on the private key, if it is provided or generate a brand new keypair.
|
|
11
10
|
* @param privateKey Optional parameter to initialize private key from
|
|
12
11
|
*/
|
|
13
|
-
constructor(privateKey?:
|
|
14
|
-
/**
|
|
15
|
-
* Returns the hex representation of the private jey
|
|
16
|
-
*/
|
|
17
|
-
get private(): string;
|
|
18
|
-
/**
|
|
19
|
-
* Returns the hex representation of the public key
|
|
20
|
-
*/
|
|
21
|
-
get public(): string;
|
|
12
|
+
constructor(privateKey?: BytesLike);
|
|
22
13
|
/**
|
|
23
14
|
* Sign the message with the private key
|
|
24
15
|
* @param message Message to sign
|
|
25
16
|
*/
|
|
26
|
-
sign(message:
|
|
27
|
-
/**
|
|
28
|
-
* Verify the signature with the public key
|
|
29
|
-
* @param signature Signed message to verify
|
|
30
|
-
* @param message Original message
|
|
31
|
-
*/
|
|
32
|
-
verify(signature: string, message: Hex): boolean;
|
|
17
|
+
sign(message: BytesLike | Hexable | number): string;
|
|
33
18
|
/**
|
|
34
19
|
* Save to the storage provided in the parameter of the function
|
|
35
20
|
* @param storage The implementation of BaseStorage interface to store and load
|
package/dist/key-pair.js
CHANGED
|
@@ -2,58 +2,32 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.KeyPair = void 0;
|
|
4
4
|
const secp256k1_1 = require("ethereum-cryptography/secp256k1");
|
|
5
|
-
const utils_1 = require("@noble/curves/abstract/utils");
|
|
6
5
|
const local_storage_1 = require("./storage/local-storage");
|
|
7
6
|
const file_storage_1 = require("./storage/file-storage");
|
|
8
|
-
|
|
7
|
+
const storage_keys_1 = require("./storage/storage-keys");
|
|
8
|
+
const signing_key_1 = require("@ethersproject/signing-key");
|
|
9
|
+
const bytes_1 = require("@ethersproject/bytes");
|
|
10
|
+
class KeyPair extends signing_key_1.SigningKey {
|
|
9
11
|
/**
|
|
10
12
|
* Initialize keypair based on the private key, if it is provided or generate a brand new keypair.
|
|
11
13
|
* @param privateKey Optional parameter to initialize private key from
|
|
12
14
|
*/
|
|
13
|
-
constructor(privateKey =
|
|
14
|
-
|
|
15
|
-
this.publicKey = (0, utils_1.bytesToHex)(secp256k1_1.secp256k1.getPublicKey(this.privateKey));
|
|
15
|
+
constructor(privateKey = secp256k1_1.secp256k1.utils.randomPrivateKey()) {
|
|
16
|
+
super(privateKey);
|
|
16
17
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Returns the hex representation of the private jey
|
|
19
|
-
*/
|
|
20
|
-
get private() {
|
|
21
|
-
return this.privateKey;
|
|
22
|
-
}
|
|
23
|
-
// public get privateHex(): string {
|
|
24
|
-
// return bytesToHex(this.private);
|
|
25
|
-
// }
|
|
26
|
-
/**
|
|
27
|
-
* Returns the hex representation of the public key
|
|
28
|
-
*/
|
|
29
|
-
get public() {
|
|
30
|
-
return this.publicKey;
|
|
31
|
-
}
|
|
32
|
-
//
|
|
33
|
-
// public get publicHex(): string {
|
|
34
|
-
// return bytesToHex(this.public);
|
|
35
|
-
// }
|
|
36
18
|
/**
|
|
37
19
|
* Sign the message with the private key
|
|
38
20
|
* @param message Message to sign
|
|
39
21
|
*/
|
|
40
22
|
sign(message) {
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Verify the signature with the public key
|
|
45
|
-
* @param signature Signed message to verify
|
|
46
|
-
* @param message Original message
|
|
47
|
-
*/
|
|
48
|
-
verify(signature, message) {
|
|
49
|
-
return secp256k1_1.secp256k1.verify(signature, message, this.public);
|
|
23
|
+
return (0, bytes_1.joinSignature)(this.signDigest((0, bytes_1.arrayify)(message, { allowMissingPrefix: true })));
|
|
50
24
|
}
|
|
51
25
|
/**
|
|
52
26
|
* Save to the storage provided in the parameter of the function
|
|
53
27
|
* @param storage The implementation of BaseStorage interface to store and load
|
|
54
28
|
*/
|
|
55
29
|
async saveToStorage(storage) {
|
|
56
|
-
await storage.save(
|
|
30
|
+
await storage.save(storage_keys_1.StorageKeys.SESSION_KEY, this.privateKey);
|
|
57
31
|
}
|
|
58
32
|
/**
|
|
59
33
|
* Save the generated key to the local storage
|
|
@@ -72,8 +46,8 @@ class KeyPair {
|
|
|
72
46
|
* @param storage The implementation of BaseStorage interface to store and load
|
|
73
47
|
*/
|
|
74
48
|
static async loadFromStorage(storage) {
|
|
75
|
-
const privateKey = await storage.get(
|
|
76
|
-
return privateKey ? new KeyPair(privateKey) : null;
|
|
49
|
+
const privateKey = await storage.get(storage_keys_1.StorageKeys.SESSION_KEY);
|
|
50
|
+
return privateKey ? new KeyPair((0, bytes_1.arrayify)(privateKey)) : null;
|
|
77
51
|
}
|
|
78
52
|
/**
|
|
79
53
|
* Load private key from the local storage and generate keypair based on it.
|
|
@@ -90,6 +64,5 @@ class KeyPair {
|
|
|
90
64
|
}
|
|
91
65
|
KeyPair.localStorage = new local_storage_1.LocalStorage();
|
|
92
66
|
KeyPair.fileStorage = new file_storage_1.FileStorage();
|
|
93
|
-
KeyPair.storageKey = 'PLAYER-KEY';
|
|
94
67
|
exports.KeyPair = KeyPair;
|
|
95
68
|
//# sourceMappingURL=key-pair.js.map
|
package/dist/key-pair.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key-pair.js","sourceRoot":"","sources":["../src/key-pair.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"key-pair.js","sourceRoot":"","sources":["../src/key-pair.ts"],"names":[],"mappings":";;;AAAA,+DAA0D;AAC1D,2DAAqD;AACrD,yDAAmD;AAEnD,yDAAmD;AACnD,4DAAsD;AACtD,gDAAwE;AAGxE,MAAa,OAAQ,SAAQ,wBAAU;IAInC;;;OAGG;IACH,YAAmB,aAAwB,qBAAS,CAAC,KAAK,CAAC,gBAAgB,EAAE;QACzE,KAAK,CAAC,UAAU,CAAC,CAAC;IACtB,CAAC;IAED;;;OAGG;IACI,IAAI,CAAC,OAAqC;QAC7C,OAAO,IAAA,qBAAa,EAAC,IAAI,CAAC,UAAU,CAAC,IAAA,gBAAQ,EAAC,OAAO,EAAE,EAAC,kBAAkB,EAAE,IAAI,EAAC,CAAC,CAAC,CAAC,CAAC;IACzF,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,aAAa,CAAC,OAAoB;QAC3C,MAAM,OAAO,CAAC,IAAI,CAAC,0BAAW,CAAC,WAAW,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACjE,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,kBAAkB;QAC3B,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACnD,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,UAAU;QACnB,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAClD,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,OAAoB;QACpD,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,0BAAW,CAAC,WAAW,CAAC,CAAC;QAC9D,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,IAAA,gBAAQ,EAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACjE,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,KAAK,CAAC,oBAAoB;QACpC,OAAO,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACzD,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,KAAK,CAAC,YAAY;QAC5B,OAAO,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACxD,CAAC;;AA9DuB,oBAAY,GAAG,IAAI,4BAAY,EAAE,CAAC;AAClC,mBAAW,GAAG,IAAI,0BAAW,EAAE,CAAC;AAF/C,0BAAO"}
|
package/dist/openfort.d.ts
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
|
-
import { SessionsApi, TransactionIntentsApi } from "./api";
|
|
1
|
+
import { SessionResponse, SessionsApi, TransactionIntentResponse, TransactionIntentsApi } from "./api";
|
|
2
|
+
import { KeyPair } from "./key-pair";
|
|
3
|
+
import { BytesLike } from "@ethersproject/bytes";
|
|
4
|
+
import { Hexable } from "@ethersproject/bytes/src.ts";
|
|
2
5
|
export default class Openfort {
|
|
3
6
|
private readonly _configuration;
|
|
4
|
-
private
|
|
5
|
-
private
|
|
7
|
+
private _sessionsApi?;
|
|
8
|
+
private _transactionsApi?;
|
|
9
|
+
private _keyPair?;
|
|
6
10
|
constructor(accessToken: string, basePath?: string);
|
|
7
|
-
get
|
|
8
|
-
get
|
|
11
|
+
get keyPair(): KeyPair;
|
|
12
|
+
protected get sessionsApi(): SessionsApi;
|
|
13
|
+
protected get transactionsApi(): TransactionIntentsApi;
|
|
14
|
+
createSessionKey(): KeyPair;
|
|
15
|
+
loadSessionKeyFromFile(): Promise<KeyPair | null>;
|
|
16
|
+
loadSessionKeyFromLocalStorage(): Promise<KeyPair | null>;
|
|
17
|
+
saveSessionKeyToFile(): Promise<void>;
|
|
18
|
+
saveSessionKeyToLocalStorage(): Promise<void>;
|
|
19
|
+
signMessage(message: BytesLike | Hexable | number): string;
|
|
20
|
+
sendSignatureSessionRequest(sessionId: string, signature: string): Promise<SessionResponse>;
|
|
21
|
+
sendSignatureTransactionIntentRequest(transactionIntentId: string, signature: string): Promise<TransactionIntentResponse>;
|
|
9
22
|
}
|
package/dist/openfort.js
CHANGED
|
@@ -1,23 +1,81 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
const configuration_1 = require("./configuration");
|
|
4
13
|
const api_1 = require("./api");
|
|
14
|
+
const key_pair_1 = require("./key-pair");
|
|
15
|
+
const http_error_handler_1 = require("./utils/http-error-handler");
|
|
5
16
|
class Openfort {
|
|
6
17
|
constructor(accessToken, basePath) {
|
|
7
18
|
this._configuration = new configuration_1.Configuration({ accessToken, basePath });
|
|
8
19
|
}
|
|
9
|
-
get
|
|
10
|
-
if (!this.
|
|
11
|
-
|
|
20
|
+
get keyPair() {
|
|
21
|
+
if (!this._keyPair) {
|
|
22
|
+
throw new Error("Session key is not initialized");
|
|
12
23
|
}
|
|
13
|
-
return this.
|
|
24
|
+
return this._keyPair;
|
|
14
25
|
}
|
|
15
|
-
get
|
|
16
|
-
if (!this.
|
|
17
|
-
this.
|
|
26
|
+
get sessionsApi() {
|
|
27
|
+
if (!this._sessionsApi) {
|
|
28
|
+
this._sessionsApi = new api_1.SessionsApi(this._configuration);
|
|
18
29
|
}
|
|
19
|
-
return this.
|
|
30
|
+
return this._sessionsApi;
|
|
31
|
+
}
|
|
32
|
+
get transactionsApi() {
|
|
33
|
+
if (!this._transactionsApi) {
|
|
34
|
+
this._transactionsApi = new api_1.TransactionIntentsApi(this._configuration);
|
|
35
|
+
}
|
|
36
|
+
return this._transactionsApi;
|
|
37
|
+
}
|
|
38
|
+
createSessionKey() {
|
|
39
|
+
this._keyPair = new key_pair_1.KeyPair();
|
|
40
|
+
return this._keyPair;
|
|
41
|
+
}
|
|
42
|
+
async loadSessionKeyFromFile() {
|
|
43
|
+
this._keyPair = await key_pair_1.KeyPair.loadFromFile();
|
|
44
|
+
return this._keyPair;
|
|
45
|
+
}
|
|
46
|
+
async loadSessionKeyFromLocalStorage() {
|
|
47
|
+
this._keyPair = await key_pair_1.KeyPair.loadFromLocalStorage();
|
|
48
|
+
return this._keyPair;
|
|
49
|
+
}
|
|
50
|
+
async saveSessionKeyToFile() {
|
|
51
|
+
return this.keyPair.saveToFile();
|
|
52
|
+
}
|
|
53
|
+
async saveSessionKeyToLocalStorage() {
|
|
54
|
+
return this.keyPair.saveToLocalStorage();
|
|
55
|
+
}
|
|
56
|
+
signMessage(message) {
|
|
57
|
+
return this.keyPair.sign(message);
|
|
58
|
+
}
|
|
59
|
+
async sendSignatureSessionRequest(sessionId, signature) {
|
|
60
|
+
const result = await this.sessionsApi.signatureSession(sessionId, signature);
|
|
61
|
+
return result.data;
|
|
62
|
+
}
|
|
63
|
+
async sendSignatureTransactionIntentRequest(transactionIntentId, signature) {
|
|
64
|
+
const result = await this.transactionsApi.signature(transactionIntentId, signature);
|
|
65
|
+
return result.data;
|
|
20
66
|
}
|
|
21
67
|
}
|
|
68
|
+
__decorate([
|
|
69
|
+
(0, http_error_handler_1.httpErrorHandler)(),
|
|
70
|
+
__metadata("design:type", Function),
|
|
71
|
+
__metadata("design:paramtypes", [String, String]),
|
|
72
|
+
__metadata("design:returntype", Promise)
|
|
73
|
+
], Openfort.prototype, "sendSignatureSessionRequest", null);
|
|
74
|
+
__decorate([
|
|
75
|
+
(0, http_error_handler_1.httpErrorHandler)(),
|
|
76
|
+
__metadata("design:type", Function),
|
|
77
|
+
__metadata("design:paramtypes", [String, String]),
|
|
78
|
+
__metadata("design:returntype", Promise)
|
|
79
|
+
], Openfort.prototype, "sendSignatureTransactionIntentRequest", null);
|
|
22
80
|
exports.default = Openfort;
|
|
23
81
|
//# sourceMappingURL=openfort.js.map
|
package/dist/openfort.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openfort.js","sourceRoot":"","sources":["../src/openfort.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"openfort.js","sourceRoot":"","sources":["../src/openfort.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,mDAA8C;AAC9C,+BAAqG;AACrG,yCAAmC;AACnC,mEAA4D;AAI5D,MAAqB,QAAQ;IAMzB,YAAY,WAAmB,EAAE,QAAiB;QAC9C,IAAI,CAAC,cAAc,GAAG,IAAI,6BAAa,CAAC,EAAC,WAAW,EAAE,QAAQ,EAAC,CAAC,CAAC;IACrE,CAAC;IAED,IAAW,OAAO;QACd,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;SACrD;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED,IAAc,WAAW;QACrB,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;YACpB,IAAI,CAAC,YAAY,GAAG,IAAI,iBAAW,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;SAC5D;QACD,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IAED,IAAc,eAAe;QACzB,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE;YACxB,IAAI,CAAC,gBAAgB,GAAG,IAAI,2BAAqB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;SAC1E;QACD,OAAO,IAAI,CAAC,gBAAgB,CAAC;IACjC,CAAC;IAEM,gBAAgB;QACnB,IAAI,CAAC,QAAQ,GAAG,IAAI,kBAAO,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAEM,KAAK,CAAC,sBAAsB;QAC/B,IAAI,CAAC,QAAQ,GAAG,MAAM,kBAAO,CAAC,YAAY,EAAE,CAAC;QAC7C,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAEM,KAAK,CAAC,8BAA8B;QACvC,IAAI,CAAC,QAAQ,GAAG,MAAM,kBAAO,CAAC,oBAAoB,EAAE,CAAC;QACrD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAEM,KAAK,CAAC,oBAAoB;QAC7B,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;IACrC,CAAC;IAEM,KAAK,CAAC,4BAA4B;QACrC,OAAO,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAC7C,CAAC;IAEM,WAAW,CAAC,OAAqC;QACpD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;IAGY,AAAN,KAAK,CAAC,2BAA2B,CAAC,SAAiB,EAAE,SAAiB;QACzE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAC7E,OAAO,MAAM,CAAC,IAAI,CAAC;IACvB,CAAC;IAGY,AAAN,KAAK,CAAC,qCAAqC,CAC9C,mBAA2B,EAC3B,SAAiB;QAEjB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,mBAAmB,EAAE,SAAS,CAAC,CAAC;QACpF,OAAO,MAAM,CAAC,IAAI,CAAC;IACvB,CAAC;CACJ;AAbgB;IADZ,IAAA,qCAAgB,GAAE;;;;2DAIlB;AAGY;IADZ,IAAA,qCAAgB,GAAE;;;;qEAOlB;AAvEL,2BAwEC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { StorageKeys } from "./storage-keys";
|
|
1
2
|
export interface BaseStorage {
|
|
2
|
-
get(key:
|
|
3
|
-
save(key:
|
|
4
|
-
remove(key:
|
|
3
|
+
get(key: StorageKeys): Promise<string | null>;
|
|
4
|
+
save(key: StorageKeys, value: string): Promise<void>;
|
|
5
|
+
remove(key: StorageKeys): Promise<void>;
|
|
5
6
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { BaseStorage } from
|
|
1
|
+
import { BaseStorage } from "./base-storage";
|
|
2
|
+
import { StorageKeys } from "./storage-keys";
|
|
2
3
|
export declare class FileStorage implements BaseStorage {
|
|
3
4
|
private readonly filePath;
|
|
4
5
|
constructor(filePath?: string);
|
|
5
|
-
get(key:
|
|
6
|
-
save(key:
|
|
7
|
-
remove(key:
|
|
6
|
+
get(key: StorageKeys): Promise<string | null>;
|
|
7
|
+
save(key: StorageKeys, value: string): Promise<void>;
|
|
8
|
+
remove(key: StorageKeys): Promise<void>;
|
|
8
9
|
private readJsonFile;
|
|
9
10
|
private readJsonFileSafe;
|
|
10
11
|
private writeJsonFile;
|
|
@@ -4,11 +4,11 @@ exports.FileStorage = void 0;
|
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const promises_1 = require("fs/promises");
|
|
6
6
|
class FileStorage {
|
|
7
|
-
constructor(filePath =
|
|
7
|
+
constructor(filePath = "openfort.data") {
|
|
8
8
|
this.filePath = (0, path_1.resolve)(filePath);
|
|
9
9
|
}
|
|
10
10
|
async get(key) {
|
|
11
|
-
const data = await this.
|
|
11
|
+
const data = await this.readJsonFileSafe();
|
|
12
12
|
return data?.[key] ?? null;
|
|
13
13
|
}
|
|
14
14
|
async save(key, value) {
|
|
@@ -22,12 +22,12 @@ class FileStorage {
|
|
|
22
22
|
await this.writeJsonFile(data);
|
|
23
23
|
}
|
|
24
24
|
async readJsonFile() {
|
|
25
|
-
const content = await (0, promises_1.readFile)(this.filePath, { encoding:
|
|
25
|
+
const content = await (0, promises_1.readFile)(this.filePath, { encoding: "utf-8" });
|
|
26
26
|
return content ? JSON.parse(content) : null;
|
|
27
27
|
}
|
|
28
28
|
async readJsonFileSafe() {
|
|
29
29
|
return ((await this.readJsonFile().catch((e) => {
|
|
30
|
-
if (e.code !==
|
|
30
|
+
if (e.code !== "ENOENT")
|
|
31
31
|
throw e.code;
|
|
32
32
|
})) ?? {});
|
|
33
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-storage.js","sourceRoot":"","sources":["../../src/storage/file-storage.ts"],"names":[],"mappings":";;;AACA,+
|
|
1
|
+
{"version":3,"file":"file-storage.js","sourceRoot":"","sources":["../../src/storage/file-storage.ts"],"names":[],"mappings":";;;AACA,+BAA6B;AAC7B,0CAAgD;AAGhD,MAAa,WAAW;IAGpB,YAAmB,WAAmB,eAAe;QACjD,IAAI,CAAC,QAAQ,GAAG,IAAA,cAAO,EAAC,QAAQ,CAAC,CAAC;IACtC,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,GAAgB;QAC7B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC3C,OAAO,IAAI,EAAE,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;IAC/B,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,GAAgB,EAAE,KAAa;QAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACrC,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAElB,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAgB;QACzB,MAAM,IAAI,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACrC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QAEjB,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAEO,KAAK,CAAC,YAAY;QACtB,MAAM,OAAO,GAAG,MAAM,IAAA,mBAAQ,EAAC,IAAI,CAAC,QAAQ,EAAE,EAAC,QAAQ,EAAE,OAAO,EAAC,CAAC,CAAC;QACnE,OAAO,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAChD,CAAC;IAEO,KAAK,CAAC,gBAAgB;QAC1B,OAAO,CACH,CAAC,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;YACnC,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ;gBAAE,MAAM,CAAC,CAAC,IAAI,CAAC;QAC1C,CAAC,CAAC,CAAC,IAAI,EAAE,CACZ,CAAC;IACN,CAAC;IAEO,KAAK,CAAC,aAAa,CAAC,IAAS;QACjC,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACrC,MAAM,IAAA,oBAAS,EAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;CACJ;AA3CD,kCA2CC"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { BaseStorage } from
|
|
1
|
+
import { BaseStorage } from "./base-storage";
|
|
2
|
+
import { StorageKeys } from "./storage-keys";
|
|
2
3
|
export declare class LocalStorage implements BaseStorage {
|
|
3
4
|
private readonly name?;
|
|
4
5
|
private static readonly _prefix;
|
|
5
6
|
private static readonly _separator;
|
|
6
|
-
constructor(name?: string
|
|
7
|
+
constructor(name?: string);
|
|
7
8
|
private formatKey;
|
|
8
9
|
private static get localStorage();
|
|
9
|
-
get(key:
|
|
10
|
-
save(key:
|
|
11
|
-
remove(key:
|
|
10
|
+
get(key: StorageKeys): Promise<string | null>;
|
|
11
|
+
save(key: StorageKeys, value: string): Promise<void>;
|
|
12
|
+
remove(key: StorageKeys): Promise<void>;
|
|
12
13
|
}
|
|
@@ -9,10 +9,10 @@ class LocalStorage {
|
|
|
9
9
|
return [LocalStorage._prefix, this.name, key].filter((n) => n).join(LocalStorage._separator);
|
|
10
10
|
}
|
|
11
11
|
static get localStorage() {
|
|
12
|
-
if (
|
|
12
|
+
if ("localStorage" in global && global.localStorage) {
|
|
13
13
|
return global.localStorage;
|
|
14
14
|
}
|
|
15
|
-
throw Error(
|
|
15
|
+
throw Error("Local storage is not available in the current context");
|
|
16
16
|
}
|
|
17
17
|
async get(key) {
|
|
18
18
|
return LocalStorage.localStorage.getItem(this.formatKey(key));
|
|
@@ -24,7 +24,7 @@ class LocalStorage {
|
|
|
24
24
|
LocalStorage.localStorage.removeItem(this.formatKey(key));
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
LocalStorage._prefix =
|
|
28
|
-
LocalStorage._separator =
|
|
27
|
+
LocalStorage._prefix = "OPENFORT";
|
|
28
|
+
LocalStorage._separator = "/";
|
|
29
29
|
exports.LocalStorage = LocalStorage;
|
|
30
30
|
//# sourceMappingURL=local-storage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-storage.js","sourceRoot":"","sources":["../../src/storage/local-storage.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"local-storage.js","sourceRoot":"","sources":["../../src/storage/local-storage.ts"],"names":[],"mappings":";;;AAGA,MAAa,YAAY;IAIrB,YAAoC,IAAa;QAAb,SAAI,GAAJ,IAAI,CAAS;IAAG,CAAC;IAE7C,SAAS,CAAC,GAAgB;QAC9B,OAAO,CAAC,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;IACjG,CAAC;IAEO,MAAM,KAAK,YAAY;QAC3B,IAAI,cAAc,IAAI,MAAM,IAAI,MAAM,CAAC,YAAY,EAAE;YACjD,OAAO,MAAM,CAAC,YAAqC,CAAC;SACvD;QACD,MAAM,KAAK,CAAC,uDAAuD,CAAC,CAAC;IACzE,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,GAAgB;QAC7B,OAAO,YAAY,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IAClE,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,GAAgB,EAAE,KAAa;QAC7C,YAAY,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IAClE,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,GAAgB;QAChC,YAAY,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9D,CAAC;;AA1BuB,oBAAO,GAAG,UAAU,CAAC;AACrB,uBAAU,GAAG,GAAG,CAAC;AAFhC,oCAAY"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StorageKeys = void 0;
|
|
4
|
+
var StorageKeys;
|
|
5
|
+
(function (StorageKeys) {
|
|
6
|
+
StorageKeys["SESSION_KEY"] = "SESSION-KEY";
|
|
7
|
+
StorageKeys["SESSION_ID"] = "SESSION-ID";
|
|
8
|
+
})(StorageKeys = exports.StorageKeys || (exports.StorageKeys = {}));
|
|
9
|
+
//# sourceMappingURL=storage-keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-keys.js","sourceRoot":"","sources":["../../src/storage/storage-keys.ts"],"names":[],"mappings":";;;AAAA,IAAY,WAGX;AAHD,WAAY,WAAW;IACnB,0CAA2B,CAAA;IAC3B,wCAAyB,CAAA;AAC7B,CAAC,EAHW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAGtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function httpErrorHandler(): <Args extends any[], R>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<(...args: Args) => Promise<R>>) => void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.httpErrorHandler = void 0;
|
|
4
|
+
const axios_1 = require("axios");
|
|
5
|
+
function parseAndPrepareHttpError(error) {
|
|
6
|
+
if (error instanceof axios_1.AxiosError && error.response?.data?.error?.message) {
|
|
7
|
+
throw new Error(error.response?.data?.error?.message);
|
|
8
|
+
}
|
|
9
|
+
throw error;
|
|
10
|
+
}
|
|
11
|
+
function httpErrorHandler() {
|
|
12
|
+
return (target, propertyKey, descriptor) => {
|
|
13
|
+
const targetMethod = descriptor.value;
|
|
14
|
+
descriptor.value = function (...args) {
|
|
15
|
+
try {
|
|
16
|
+
const result = targetMethod.apply(this, args);
|
|
17
|
+
if (result instanceof Promise) {
|
|
18
|
+
return result.catch((error) => {
|
|
19
|
+
throw parseAndPrepareHttpError(error);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
throw parseAndPrepareHttpError(error);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
exports.httpErrorHandler = httpErrorHandler;
|
|
31
|
+
//# sourceMappingURL=http-error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-error-handler.js","sourceRoot":"","sources":["../../src/utils/http-error-handler.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AAEjC,SAAS,wBAAwB,CAAI,KAAQ;IACzC,IAAI,KAAK,YAAY,kBAAU,IAAI,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE;QACrE,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;KACzD;IACD,MAAM,KAAK,CAAC;AAChB,CAAC;AAED,SAAgB,gBAAgB;IAC5B,OAAO,CACH,MAAc,EACd,WAAmB,EACnB,UAAkE,EACpE,EAAE;QACA,MAAM,YAAY,GAAG,UAAU,CAAC,KAAM,CAAC;QAEvC,UAAU,CAAC,KAAK,GAAG,UAAU,GAAG,IAAU;YACtC,IAAI;gBACA,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBAC9C,IAAI,MAAM,YAAY,OAAO,EAAE;oBAC3B,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;wBAC1B,MAAM,wBAAwB,CAAC,KAAK,CAAC,CAAC;oBAC1C,CAAC,CAAC,CAAC;iBACN;gBACD,OAAO,MAAM,CAAC;aACjB;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,wBAAwB,CAAC,KAAK,CAAC,CAAC;aACzC;QACL,CAAC,CAAC;IACN,CAAC,CAAC;AACN,CAAC;AAtBD,4CAsBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfort/openfort-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "",
|
|
6
6
|
"repository": {
|
|
@@ -31,6 +31,8 @@
|
|
|
31
31
|
"typescript": "^5.0.4"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
+
"@ethersproject/bytes": "^5.7.0",
|
|
35
|
+
"@ethersproject/signing-key": "^5.7.0",
|
|
34
36
|
"axios": "^1.4.0",
|
|
35
37
|
"es6-promise": "^4.2.8",
|
|
36
38
|
"ethereum-cryptography": "^2.0.0",
|
package/tsconfig.json
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"outDir": "dist",
|
|
4
3
|
"rootDir": "src",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
4
|
+
"outDir": "dist",
|
|
5
|
+
"typeRoots": ["node_modules/@types"],
|
|
6
|
+
"lib": ["es2021", "dom"],
|
|
7
7
|
"module": "commonjs",
|
|
8
|
-
"composite": true,
|
|
9
8
|
"target": "es2021",
|
|
10
|
-
"
|
|
11
|
-
"
|
|
9
|
+
"newLine": "LF",
|
|
10
|
+
"composite": true,
|
|
11
|
+
"declaration": true,
|
|
12
12
|
"downlevelIteration": true,
|
|
13
|
+
"emitDecoratorMetadata": true,
|
|
14
|
+
"esModuleInterop": true,
|
|
13
15
|
"experimentalDecorators": true,
|
|
14
|
-
"
|
|
16
|
+
"noFallthroughCasesInSwitch": true,
|
|
17
|
+
"noImplicitAny": false,
|
|
18
|
+
"noImplicitReturns": true,
|
|
19
|
+
"noImplicitThis": true,
|
|
15
20
|
"noUnusedLocals": false,
|
|
16
|
-
"strictNullChecks": true,
|
|
17
|
-
"newLine": "LF",
|
|
18
21
|
"noUnusedParameters": false,
|
|
19
|
-
"
|
|
20
|
-
"noImplicitThis": true,
|
|
21
|
-
"noImplicitReturns": true,
|
|
22
|
-
"noFallthroughCasesInSwitch": true,
|
|
22
|
+
"sourceMap": true,
|
|
23
23
|
"strictBindCallApply": true,
|
|
24
|
-
"esModuleInterop": true
|
|
25
24
|
},
|
|
26
25
|
"exclude": [
|
|
27
26
|
"dist",
|