@ckb-ccc/joy-id 1.0.19 → 1.0.21

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 CHANGED
@@ -1,5 +1,15 @@
1
1
  # @ckb-ccc/joy-id
2
2
 
3
+ ## 1.0.21
4
+ ### Patch Changes
5
+
6
+
7
+
8
+ - [`d94bbb3`](https://github.com/ckb-devrel/ccc/commit/d94bbb3b46e1bb0d54be8f4d5f04fb042074bddf) Thanks [@yixyxiu](https://github.com/yixyxiu)! - fix(joy-id): resolve race condition in Bitcoin signer connection storage
9
+
10
+ - Updated dependencies [[`07fc9fe`](https://github.com/ckb-devrel/ccc/commit/07fc9fe196115bf4b341e7b657927987956a6d7c), [`0e7cd8f`](https://github.com/ckb-devrel/ccc/commit/0e7cd8f6ca191186852c84e44db2fc0e1bb26d9b), [`0008150`](https://github.com/ckb-devrel/ccc/commit/00081509e54e52af999e48feec11c90d2c649ab9), [`91f6027`](https://github.com/ckb-devrel/ccc/commit/91f60277c75773fad509f945eef8397ef1061cd1), [`5061511`](https://github.com/ckb-devrel/ccc/commit/506151120fcd1a80b6d38e074b7944164047e76f), [`82531c9`](https://github.com/ckb-devrel/ccc/commit/82531c9357bf29ebe1c222eb000d1fd03d0a96e6), [`82531c9`](https://github.com/ckb-devrel/ccc/commit/82531c9357bf29ebe1c222eb000d1fd03d0a96e6), [`40fcd50`](https://github.com/ckb-devrel/ccc/commit/40fcd50639ce32bee1fc54497b22f4871807e98a), [`82f5a45`](https://github.com/ckb-devrel/ccc/commit/82f5a45fd35968673be93f09bdd59ca79a7afb6e), [`82531c9`](https://github.com/ckb-devrel/ccc/commit/82531c9357bf29ebe1c222eb000d1fd03d0a96e6), [`46c61d4`](https://github.com/ckb-devrel/ccc/commit/46c61d48d5289a76385463bc7783b7cbfb05ed99)]:
11
+ - @ckb-ccc/core@1.11.0
12
+
3
13
  ## 1.0.19
4
14
  ### Patch Changes
5
15
 
package/dist/btc/index.js CHANGED
@@ -115,7 +115,7 @@ export class BitcoinSigner extends ccc.SignerBtc {
115
115
  keyType: res.keyType,
116
116
  };
117
117
  await Promise.all([
118
- this.connectionsRepo.set({ uri: config.joyidAppURL, addressType: `btc-${res.btcAddressType}` }, this.connection),
118
+ this.connectionsRepo.set({ uri: config.joyidAppURL, addressType: `btc-${this.addressType}` }, this.connection),
119
119
  this.connectionsRepo.set({ uri: config.joyidAppURL, addressType: "btc-auto" }, this.connection),
120
120
  ]);
121
121
  }
@@ -59,6 +59,7 @@ export interface ConnectionsRepo {
59
59
  */
60
60
  export declare class ConnectionsRepoLocalStorage implements ConnectionsRepo {
61
61
  private readonly storageKey;
62
+ private operationLock;
62
63
  /**
63
64
  * Creates an instance of ConnectionsRepoLocalStorage.
64
65
  * @param [storageKey="ccc-joy-id-signer"] - The local storage key.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connectionsStorage/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,CAAC,EAAE,eAAe,EAClB,MAAM,EAAE,eAAe,GACtB,OAAO,CAET;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,GAAG,CAAC;IAC5B;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,GAAG,CAAC,QAAQ,EAAE,eAAe,GAA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WAAW,eAAe;IAC9B;;;;OAIG;IACH,GAAG,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;IAEhE;;;;;OAKG;IACH,GAAG,CACD,QAAQ,EAAE,eAAe,EACzB,UAAU,EAAE,UAAU,GAAG,SAAS,GACjC,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB;AAED;;GAEG;AACH,qBAAa,2BAA4B,YAAW,eAAe;IAOrD,OAAO,CAAC,QAAQ,CAAC,UAAU;IANvC,OAAO,CAAC,aAAa,CAAoC;IAEzD;;;OAGG;gBAC0B,UAAU,SAAsB;IAE7D;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,CAAC,eAAe,EAAE,UAAU,CAAC,EAAE,CAAC;IAOjE;;;;OAIG;IACG,GAAG,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAMrE;;;;;OAKG;IACG,GAAG,CACP,QAAQ,EAAE,eAAe,EACzB,UAAU,EAAE,UAAU,GAAG,SAAS,GACjC,OAAO,CAAC,IAAI,CAAC;CAgCjB"}
@@ -17,6 +17,7 @@ export class ConnectionsRepoLocalStorage {
17
17
  */
18
18
  constructor(storageKey = "ccc-joy-id-signer") {
19
19
  this.storageKey = storageKey;
20
+ this.operationLock = Promise.resolve();
20
21
  }
21
22
  /**
22
23
  * Reads all connections from local storage.
@@ -40,19 +41,25 @@ export class ConnectionsRepoLocalStorage {
40
41
  * @returns
41
42
  */
42
43
  async set(selector, connection) {
43
- const connections = await this.readConnections();
44
- if (connection) {
45
- const existed = connections.find(([s]) => isSelectorMatch(s, selector));
46
- if (existed) {
47
- existed[1] = connection;
44
+ const operation = this.operationLock
45
+ .catch(() => undefined)
46
+ .then(async () => {
47
+ const connections = await this.readConnections();
48
+ if (connection) {
49
+ const existed = connections.find(([s]) => isSelectorMatch(s, selector));
50
+ if (existed) {
51
+ existed[1] = connection;
52
+ }
53
+ else {
54
+ connections.push([selector, connection]);
55
+ }
56
+ window.localStorage.setItem(this.storageKey, JSON.stringify(connections));
48
57
  }
49
58
  else {
50
- connections.push([selector, connection]);
59
+ window.localStorage.setItem(this.storageKey, JSON.stringify(connections.filter(([s]) => !isSelectorMatch(s, selector))));
51
60
  }
52
- window.localStorage.setItem(this.storageKey, JSON.stringify(connections));
53
- }
54
- else {
55
- window.localStorage.setItem(this.storageKey, JSON.stringify(connections.filter(([s]) => !isSelectorMatch(s, selector))));
56
- }
61
+ });
62
+ this.operationLock = operation;
63
+ await operation;
57
64
  }
58
65
  }
@@ -118,7 +118,7 @@ class BitcoinSigner extends core_1.ccc.SignerBtc {
118
118
  keyType: res.keyType,
119
119
  };
120
120
  await Promise.all([
121
- this.connectionsRepo.set({ uri: config.joyidAppURL, addressType: `btc-${res.btcAddressType}` }, this.connection),
121
+ this.connectionsRepo.set({ uri: config.joyidAppURL, addressType: `btc-${this.addressType}` }, this.connection),
122
122
  this.connectionsRepo.set({ uri: config.joyidAppURL, addressType: "btc-auto" }, this.connection),
123
123
  ]);
124
124
  }
@@ -59,6 +59,7 @@ export interface ConnectionsRepo {
59
59
  */
60
60
  export declare class ConnectionsRepoLocalStorage implements ConnectionsRepo {
61
61
  private readonly storageKey;
62
+ private operationLock;
62
63
  /**
63
64
  * Creates an instance of ConnectionsRepoLocalStorage.
64
65
  * @param [storageKey="ccc-joy-id-signer"] - The local storage key.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connectionsStorage/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,CAAC,EAAE,eAAe,EAClB,MAAM,EAAE,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GAKG;AACH,wBAAgB,eAAe,CAC7B,CAAC,EAAE,eAAe,EAClB,MAAM,EAAE,eAAe,GACtB,OAAO,CAET;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,GAAG,CAAC;IAC5B;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,GAAG,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;IAEhE;;;;;OAKG;IACH,GAAG,CACD,QAAQ,EAAE,eAAe,EACzB,UAAU,EAAE,UAAU,GAAG,SAAS,GACjC,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB;AAED;;GAEG;AACH,qBAAa,2BAA4B,YAAW,eAAe;IAOrD,OAAO,CAAC,QAAQ,CAAC,UAAU;IANvC,OAAO,CAAC,aAAa,CAAoC;IAEzD;;;OAGG;gBAC0B,UAAU,SAAsB;IAE7D;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,CAAC,eAAe,EAAE,UAAU,CAAC,EAAE,CAAC;IAOjE;;;;OAIG;IACG,GAAG,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAMrE;;;;;OAKG;IACG,GAAG,CACP,QAAQ,EAAE,eAAe,EACzB,UAAU,EAAE,UAAU,GAAG,SAAS,GACjC,OAAO,CAAC,IAAI,CAAC;CAgCjB"}
@@ -21,6 +21,7 @@ class ConnectionsRepoLocalStorage {
21
21
  */
22
22
  constructor(storageKey = "ccc-joy-id-signer") {
23
23
  this.storageKey = storageKey;
24
+ this.operationLock = Promise.resolve();
24
25
  }
25
26
  /**
26
27
  * Reads all connections from local storage.
@@ -44,20 +45,26 @@ class ConnectionsRepoLocalStorage {
44
45
  * @returns
45
46
  */
46
47
  async set(selector, connection) {
47
- const connections = await this.readConnections();
48
- if (connection) {
49
- const existed = connections.find(([s]) => isSelectorMatch(s, selector));
50
- if (existed) {
51
- existed[1] = connection;
48
+ const operation = this.operationLock
49
+ .catch(() => undefined)
50
+ .then(async () => {
51
+ const connections = await this.readConnections();
52
+ if (connection) {
53
+ const existed = connections.find(([s]) => isSelectorMatch(s, selector));
54
+ if (existed) {
55
+ existed[1] = connection;
56
+ }
57
+ else {
58
+ connections.push([selector, connection]);
59
+ }
60
+ window.localStorage.setItem(this.storageKey, JSON.stringify(connections));
52
61
  }
53
62
  else {
54
- connections.push([selector, connection]);
63
+ window.localStorage.setItem(this.storageKey, JSON.stringify(connections.filter(([s]) => !isSelectorMatch(s, selector))));
55
64
  }
56
- window.localStorage.setItem(this.storageKey, JSON.stringify(connections));
57
- }
58
- else {
59
- window.localStorage.setItem(this.storageKey, JSON.stringify(connections.filter(([s]) => !isSelectorMatch(s, selector))));
60
- }
65
+ });
66
+ this.operationLock = operation;
67
+ await operation;
61
68
  }
62
69
  }
63
70
  exports.ConnectionsRepoLocalStorage = ConnectionsRepoLocalStorage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/joy-id",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "description": "Connector's support for JoyID",
5
5
  "author": "Hanssen0 <hanssen0@hanssen0.com>",
6
6
  "license": "MIT",
@@ -38,7 +38,7 @@
38
38
  "dependencies": {
39
39
  "@joyid/ckb": "^1.1.1",
40
40
  "@joyid/common": "^0.2.0",
41
- "@ckb-ccc/core": "1.9.1"
41
+ "@ckb-ccc/core": "1.11.0"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "rimraf ./dist && rimraf ./dist.commonjs && tsc && tsc --project tsconfig.commonjs.json && copyfiles -u 2 misc/basedirs/**/* .",
@@ -7,7 +7,7 @@
7
7
  const config = {
8
8
  singleQuote: false,
9
9
  trailingComma: "all",
10
- plugins: [import.meta.resolve("prettier-plugin-organize-imports")],
10
+ plugins: ["prettier-plugin-organize-imports"],
11
11
  };
12
12
 
13
13
  export default config;
package/src/btc/index.ts CHANGED
@@ -145,7 +145,7 @@ export class BitcoinSigner extends ccc.SignerBtc {
145
145
  };
146
146
  await Promise.all([
147
147
  this.connectionsRepo.set(
148
- { uri: config.joyidAppURL, addressType: `btc-${res.btcAddressType}` },
148
+ { uri: config.joyidAppURL, addressType: `btc-${this.addressType}` },
149
149
  this.connection,
150
150
  ),
151
151
  this.connectionsRepo.set(
@@ -72,6 +72,8 @@ export interface ConnectionsRepo {
72
72
  * Class representing a local storage-based repository for managing connections.
73
73
  */
74
74
  export class ConnectionsRepoLocalStorage implements ConnectionsRepo {
75
+ private operationLock: Promise<void> = Promise.resolve();
76
+
75
77
  /**
76
78
  * Creates an instance of ConnectionsRepoLocalStorage.
77
79
  * @param [storageKey="ccc-joy-id-signer"] - The local storage key.
@@ -110,23 +112,35 @@ export class ConnectionsRepoLocalStorage implements ConnectionsRepo {
110
112
  selector: AccountSelector,
111
113
  connection: Connection | undefined,
112
114
  ): Promise<void> {
113
- const connections = await this.readConnections();
115
+ const operation = this.operationLock
116
+ .catch(() => undefined)
117
+ .then(async () => {
118
+ const connections = await this.readConnections();
119
+
120
+ if (connection) {
121
+ const existed = connections.find(([s]) =>
122
+ isSelectorMatch(s, selector),
123
+ );
124
+ if (existed) {
125
+ existed[1] = connection;
126
+ } else {
127
+ connections.push([selector, connection]);
128
+ }
129
+ window.localStorage.setItem(
130
+ this.storageKey,
131
+ JSON.stringify(connections),
132
+ );
133
+ } else {
134
+ window.localStorage.setItem(
135
+ this.storageKey,
136
+ JSON.stringify(
137
+ connections.filter(([s]) => !isSelectorMatch(s, selector)),
138
+ ),
139
+ );
140
+ }
141
+ });
114
142
 
115
- if (connection) {
116
- const existed = connections.find(([s]) => isSelectorMatch(s, selector));
117
- if (existed) {
118
- existed[1] = connection;
119
- } else {
120
- connections.push([selector, connection]);
121
- }
122
- window.localStorage.setItem(this.storageKey, JSON.stringify(connections));
123
- } else {
124
- window.localStorage.setItem(
125
- this.storageKey,
126
- JSON.stringify(
127
- connections.filter(([s]) => !isSelectorMatch(s, selector)),
128
- ),
129
- );
130
- }
143
+ this.operationLock = operation;
144
+ await operation;
131
145
  }
132
146
  }