Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit e3acf9b

Browse files
authored
fix: use Key.asKey instead of instanceOf (#3877)
Using `instanceOf` is not reliable since instances of classes can cross the CLS/ESM boundary and/or come from different browser bundles. Instead see if we can treat what we've been handed as a `Key` by using the `Key.asKey` method. Fixes #3852
1 parent 88c9921 commit e3acf9b

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

.github/workflows/test.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
steps:
7171
- uses: actions/checkout@v2
7272
with:
73-
fetch-depth: ${{ github.event.pull_request.commits }}
73+
fetch-depth: 0
7474
- uses: actions/setup-node@v2
7575
with:
7676
node-version: ${{ matrix.node }}
@@ -107,7 +107,7 @@ jobs:
107107
steps:
108108
- uses: actions/checkout@v2
109109
with:
110-
fetch-depth: ${{ github.event.pull_request.commits }}
110+
fetch-depth: 0
111111
- uses: actions/setup-node@v2
112112
with:
113113
node-version: 16
@@ -136,7 +136,7 @@ jobs:
136136
steps:
137137
- uses: actions/checkout@v2
138138
with:
139-
fetch-depth: ${{ github.event.pull_request.commits }}
139+
fetch-depth: 0
140140
- uses: actions/setup-node@v2
141141
with:
142142
node-version: 16
@@ -167,7 +167,7 @@ jobs:
167167
steps:
168168
- uses: actions/checkout@v2
169169
with:
170-
fetch-depth: ${{ github.event.pull_request.commits }}
170+
fetch-depth: 0
171171
- uses: actions/setup-node@v2
172172
with:
173173
node-version: 16
@@ -205,7 +205,7 @@ jobs:
205205
steps:
206206
- uses: actions/checkout@v2
207207
with:
208-
fetch-depth: ${{ github.event.pull_request.commits }}
208+
fetch-depth: 0
209209
- uses: actions/setup-node@v2
210210
with:
211211
node-version: 16
@@ -246,7 +246,7 @@ jobs:
246246
steps:
247247
- uses: actions/checkout@v2
248248
with:
249-
fetch-depth: ${{ github.event.pull_request.commits }}
249+
fetch-depth: 0
250250
- uses: actions/setup-node@v2
251251
with:
252252
node-version: 16
@@ -275,7 +275,7 @@ jobs:
275275
steps:
276276
- uses: actions/checkout@v2
277277
with:
278-
fetch-depth: ${{ github.event.pull_request.commits }}
278+
fetch-depth: 0
279279
- uses: actions/setup-node@v2
280280
with:
281281
node-version: 16

packages/ipfs-core-types/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
],
4242
"license": "(Apache-2.0 OR MIT)",
4343
"dependencies": {
44-
"interface-datastore": "^5.0.0",
44+
"interface-datastore": "^5.2.0",
4545
"multiaddr": "^10.0.0",
4646
"multiformats": "^9.4.1"
4747
},

packages/ipfs-core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"hamt-sharding": "^2.0.0",
7575
"hashlru": "^2.3.0",
7676
"interface-blockstore": "^1.0.0",
77-
"interface-datastore": "^5.0.0",
77+
"interface-datastore": "^5.2.0",
7878
"ipfs-bitswap": "^6.0.0",
7979
"ipfs-core-types": "^0.7.2",
8080
"ipfs-core-utils": "^0.10.4",

packages/ipfs-core/src/ipns/publisher.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ class IpnsPublisher {
9292
* @param {IPNSEntry} entry
9393
*/
9494
async _publishEntry (key, entry) {
95-
if (!(key instanceof Key)) {
95+
const k = Key.asKey(key)
96+
97+
if (!k) {
9698
const errMsg = 'datastore key does not have a valid format'
9799

98100
log.error(errMsg)
@@ -112,12 +114,12 @@ class IpnsPublisher {
112114

113115
// Add record to routing (buffer key)
114116
try {
115-
const res = await this._routing.put(key.uint8Array(), entryData)
116-
log(`ipns record for ${uint8ArrayToString(key.uint8Array(), 'base64')} was stored in the routing`)
117+
const res = await this._routing.put(k.uint8Array(), entryData)
118+
log(`ipns record for ${uint8ArrayToString(k.uint8Array(), 'base64')} was stored in the routing`)
117119

118120
return res
119121
} catch (err) {
120-
const errMsg = `ipns record for ${uint8ArrayToString(key.uint8Array(), 'base64')} could not be stored in the routing`
122+
const errMsg = `ipns record for ${uint8ArrayToString(k.uint8Array(), 'base64')} could not be stored in the routing`
121123
log.error(errMsg)
122124
log.error(err)
123125

@@ -130,7 +132,9 @@ class IpnsPublisher {
130132
* @param {PublicKey} publicKey
131133
*/
132134
async _publishPublicKey (key, publicKey) {
133-
if (!(key instanceof Key)) {
135+
const k = Key.asKey(key)
136+
137+
if (!k) {
134138
const errMsg = 'datastore key does not have a valid format'
135139
log.error(errMsg)
136140

@@ -146,12 +150,12 @@ class IpnsPublisher {
146150

147151
// Add public key to routing (buffer key)
148152
try {
149-
const res = await this._routing.put(key.uint8Array(), publicKey.bytes)
150-
log(`public key for ${uint8ArrayToString(key.uint8Array(), 'base64')} was stored in the routing`)
153+
const res = await this._routing.put(k.uint8Array(), publicKey.bytes)
154+
log(`public key for ${uint8ArrayToString(k.uint8Array(), 'base64')} was stored in the routing`)
151155

152156
return res
153157
} catch (err) {
154-
const errMsg = `public key for ${uint8ArrayToString(key.uint8Array(), 'base64')} could not be stored in the routing`
158+
const errMsg = `public key for ${uint8ArrayToString(k.uint8Array(), 'base64')} could not be stored in the routing`
155159
log.error(errMsg)
156160
log.error(err)
157161

0 commit comments

Comments
 (0)