Skip to content

Commit 063fc85

Browse files
authored
chore: update deps (#126)
BREAKING CHANGE: uses new peer-id class and supporting ecosystem modules
1 parent d567530 commit 063fc85

File tree

5 files changed

+131
-121
lines changed

5 files changed

+131
-121
lines changed

package.json

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"prepare:proto": "pbjs -t static-module -w commonjs -r ipfs-ipns --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/pb/ipns.js src/pb/ipns.proto",
1111
"prepare:proto-types": "pbts -o src/pb/ipns.d.ts src/pb/ipns.js",
1212
"prepare:types": "aegir build --no-bundle",
13-
"lint": "aegir lint",
13+
"lint": "aegir ts -p check &&aegir lint",
1414
"release": "aegir release",
1515
"release-minor": "aegir release --type minor",
1616
"release-major": "aegir release --type major",
@@ -44,22 +44,27 @@
4444
"cborg": "^1.3.3",
4545
"debug": "^4.2.0",
4646
"err-code": "^3.0.1",
47-
"interface-datastore": "^4.0.2",
48-
"libp2p-crypto": "^0.19.0",
47+
"interface-datastore": "^5.1.1",
48+
"libp2p-crypto": "^0.19.5",
4949
"long": "^4.0.0",
50-
"multibase": "^4.0.2",
51-
"multihashes": "^4.0.2",
52-
"peer-id": "^0.14.2",
50+
"multiformats": "^9.2.0",
51+
"peer-id": "^0.15.0",
5352
"protobufjs": "^6.10.2",
5453
"timestamp-nano": "^1.0.0",
5554
"uint8arrays": "^2.0.5"
5655
},
5756
"devDependencies": {
5857
"@types/debug": "^4.1.5",
59-
"aegir": "^33.1.0",
58+
"aegir": "^34.0.1",
6059
"npm-run-all": "^4.1.5",
6160
"util": "^0.12.3"
6261
},
62+
"eslintConfig": {
63+
"extends": "ipfs",
64+
"ignorePatterns": [
65+
"src/pb/ipns.d.ts"
66+
]
67+
},
6368
"contributors": [
6469
"Vasco Santos <[email protected]>",
6570
"Alex Potsides <[email protected]>",

src/index.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ const NanoDate = require('timestamp-nano')
44
const { Key } = require('interface-datastore')
55
const crypto = require('libp2p-crypto')
66
const PeerId = require('peer-id')
7-
const multihash = require('multihashes')
7+
const Digest = require('multiformats/hashes/digest')
8+
const { identity } = require('multiformats/hashes/identity')
89
const errCode = require('err-code')
9-
const multibase = require('multibase')
10+
const { base32upper } = require('multiformats/bases/base32')
1011
const uint8ArrayFromString = require('uint8arrays/from-string')
1112
const uint8ArrayToString = require('uint8arrays/to-string')
1213
const uint8ArrayConcat = require('uint8arrays/concat')
@@ -25,7 +26,7 @@ const {
2526
const { parseRFC3339 } = require('./utils')
2627
const ERRORS = require('./errors')
2728

28-
const ID_MULTIHASH_CODE = multihash.names.identity
29+
const ID_MULTIHASH_CODE = identity.code
2930

3031
const namespace = '/ipns/'
3132

@@ -310,7 +311,7 @@ const extractPublicKey = (peerId, entry) => {
310311
*
311312
* @param {Uint8Array} key
312313
*/
313-
const rawStdEncoding = (key) => uint8ArrayToString(multibase.encode('base32', key)).slice(1).toUpperCase()
314+
const rawStdEncoding = (key) => base32upper.encode(key).slice(1)
314315

315316
/**
316317
* Get key for storing the record locally.
@@ -402,13 +403,13 @@ const ipnsEntryDataForV2Sig = (data) => {
402403
* @param {PeerId} peerId
403404
*/
404405
const extractPublicKeyFromId = (peerId) => {
405-
const decodedId = multihash.decode(peerId.id)
406+
const digest = Digest.decode(peerId.id)
406407

407-
if (decodedId.code !== ID_MULTIHASH_CODE) {
408+
if (digest.code !== ID_MULTIHASH_CODE) {
408409
return null
409410
}
410411

411-
return crypto.keys.unmarshalPublicKey(decodedId.digest)
412+
return crypto.keys.unmarshalPublicKey(digest.digest)
412413
}
413414

414415
/**
@@ -452,8 +453,8 @@ const validator = {
452453
*/
453454
validate: async (marshalledData, key) => {
454455
const receivedEntry = unmarshal(marshalledData)
455-
const bufferId = key.slice('/ipns/'.length)
456-
const peerId = PeerId.createFromBytes(bufferId)
456+
const bufferId = uint8ArrayToString(key).substring('/ipns/'.length)
457+
const peerId = PeerId.parse(bufferId)
457458

458459
// extract public key
459460
const pubKey = extractPublicKey(peerId, receivedEntry)

src/pb/ipns.d.ts

Lines changed: 100 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,120 @@
1-
import * as $protobuf from "protobufjs";
1+
import * as $protobuf from 'protobufjs'
22
/** Properties of an IpnsEntry. */
33
export interface IIpnsEntry {
44

5-
/** IpnsEntry value */
6-
value?: (Uint8Array|null);
5+
/** IpnsEntry value */
6+
value?: (Uint8Array|null)
77

8-
/** IpnsEntry signature */
9-
signature?: (Uint8Array|null);
8+
/** IpnsEntry signature */
9+
signature?: (Uint8Array|null)
1010

11-
/** IpnsEntry validityType */
12-
validityType?: (IpnsEntry.ValidityType|null);
11+
/** IpnsEntry validityType */
12+
validityType?: (IpnsEntry.ValidityType|null)
1313

14-
/** IpnsEntry validity */
15-
validity?: (Uint8Array|null);
14+
/** IpnsEntry validity */
15+
validity?: (Uint8Array|null)
1616

17-
/** IpnsEntry sequence */
18-
sequence?: (number|Long|null);
17+
/** IpnsEntry sequence */
18+
sequence?: (number|Long|null)
1919

20-
/** IpnsEntry ttl */
21-
ttl?: (number|Long|null);
20+
/** IpnsEntry ttl */
21+
ttl?: (number|Long|null)
2222

23-
/** IpnsEntry pubKey */
24-
pubKey?: (Uint8Array|null);
23+
/** IpnsEntry pubKey */
24+
pubKey?: (Uint8Array|null)
2525

26-
/** IpnsEntry signatureV2 */
27-
signatureV2?: (Uint8Array|null);
26+
/** IpnsEntry signatureV2 */
27+
signatureV2?: (Uint8Array|null)
2828

29-
/** IpnsEntry data */
30-
data?: (Uint8Array|null);
29+
/** IpnsEntry data */
30+
data?: (Uint8Array|null)
3131
}
3232

3333
/** Represents an IpnsEntry. */
3434
export class IpnsEntry implements IIpnsEntry {
35-
36-
/**
37-
* Constructs a new IpnsEntry.
38-
* @param [p] Properties to set
39-
*/
40-
constructor(p?: IIpnsEntry);
41-
42-
/** IpnsEntry value. */
43-
public value: Uint8Array;
44-
45-
/** IpnsEntry signature. */
46-
public signature: Uint8Array;
47-
48-
/** IpnsEntry validityType. */
49-
public validityType: IpnsEntry.ValidityType;
50-
51-
/** IpnsEntry validity. */
52-
public validity: Uint8Array;
53-
54-
/** IpnsEntry sequence. */
55-
public sequence: (number|Long);
56-
57-
/** IpnsEntry ttl. */
58-
public ttl: (number|Long);
59-
60-
/** IpnsEntry pubKey. */
61-
public pubKey: Uint8Array;
62-
63-
/** IpnsEntry signatureV2. */
64-
public signatureV2: Uint8Array;
65-
66-
/** IpnsEntry data. */
67-
public data: Uint8Array;
68-
69-
/**
70-
* Encodes the specified IpnsEntry message. Does not implicitly {@link IpnsEntry.verify|verify} messages.
71-
* @param m IpnsEntry message or plain object to encode
72-
* @param [w] Writer to encode to
73-
* @returns Writer
74-
*/
75-
public static encode(m: IIpnsEntry, w?: $protobuf.Writer): $protobuf.Writer;
76-
77-
/**
78-
* Decodes an IpnsEntry message from the specified reader or buffer.
79-
* @param r Reader or buffer to decode from
80-
* @param [l] Message length if known beforehand
81-
* @returns IpnsEntry
82-
* @throws {Error} If the payload is not a reader or valid buffer
83-
* @throws {$protobuf.util.ProtocolError} If required fields are missing
84-
*/
85-
public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): IpnsEntry;
86-
87-
/**
88-
* Creates an IpnsEntry message from a plain object. Also converts values to their respective internal types.
89-
* @param d Plain object
90-
* @returns IpnsEntry
91-
*/
92-
public static fromObject(d: { [k: string]: any }): IpnsEntry;
93-
94-
/**
95-
* Creates a plain object from an IpnsEntry message. Also converts values to other types if specified.
96-
* @param m IpnsEntry
97-
* @param [o] Conversion options
98-
* @returns Plain object
99-
*/
100-
public static toObject(m: IpnsEntry, o?: $protobuf.IConversionOptions): { [k: string]: any };
101-
102-
/**
103-
* Converts this IpnsEntry to JSON.
104-
* @returns JSON object
105-
*/
106-
public toJSON(): { [k: string]: any };
35+
/**
36+
* Constructs a new IpnsEntry.
37+
*
38+
* @param [p] - Properties to set
39+
*/
40+
constructor (p?: IIpnsEntry);
41+
42+
/** IpnsEntry value. */
43+
public value: Uint8Array
44+
45+
/** IpnsEntry signature. */
46+
public signature: Uint8Array
47+
48+
/** IpnsEntry validityType. */
49+
public validityType: IpnsEntry.ValidityType
50+
51+
/** IpnsEntry validity. */
52+
public validity: Uint8Array
53+
54+
/** IpnsEntry sequence. */
55+
public sequence: (number|Long)
56+
57+
/** IpnsEntry ttl. */
58+
public ttl: (number|Long)
59+
60+
/** IpnsEntry pubKey. */
61+
public pubKey: Uint8Array
62+
63+
/** IpnsEntry signatureV2. */
64+
public signatureV2: Uint8Array
65+
66+
/** IpnsEntry data. */
67+
public data: Uint8Array
68+
69+
/**
70+
* Encodes the specified IpnsEntry message. Does not implicitly {@link IpnsEntry.verify|verify} messages.
71+
*
72+
* @param m - IpnsEntry message or plain object to encode
73+
* @param [w] - Writer to encode to
74+
* @returns Writer
75+
*/
76+
public static encode (m: IIpnsEntry, w?: $protobuf.Writer): $protobuf.Writer;
77+
78+
/**
79+
* Decodes an IpnsEntry message from the specified reader or buffer.
80+
*
81+
* @param r - Reader or buffer to decode from
82+
* @param [l] - Message length if known beforehand
83+
* @returns IpnsEntry
84+
* @throws {Error} If the payload is not a reader or valid buffer
85+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
86+
*/
87+
public static decode (r: ($protobuf.Reader|Uint8Array), l?: number): IpnsEntry;
88+
89+
/**
90+
* Creates an IpnsEntry message from a plain object. Also converts values to their respective internal types.
91+
*
92+
* @param d - Plain object
93+
* @returns IpnsEntry
94+
*/
95+
public static fromObject (d: { [k: string]: any }): IpnsEntry;
96+
97+
/**
98+
* Creates a plain object from an IpnsEntry message. Also converts values to other types if specified.
99+
*
100+
* @param m - IpnsEntry
101+
* @param [o] - Conversion options
102+
* @returns Plain object
103+
*/
104+
public static toObject (m: IpnsEntry, o?: $protobuf.IConversionOptions): { [k: string]: any };
105+
106+
/**
107+
* Converts this IpnsEntry to JSON.
108+
*
109+
* @returns JSON object
110+
*/
111+
public toJSON (): { [k: string]: any };
107112
}
108113

109114
export namespace IpnsEntry {
110115

111-
/** ValidityType enum. */
112-
enum ValidityType {
113-
EOL = 0
114-
}
116+
/** ValidityType enum. */
117+
enum ValidityType {
118+
EOL = 0
119+
}
115120
}

src/types.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import ValidityType from './pb/ipns'
33

44
export interface IPNSEntry {
5-
value: Uint8Array, // value to be stored in the record
6-
signature: Uint8Array, // signature of the record
7-
validityType: ValidityType, // Type of validation being used
8-
validity: Uint8Array, // expiration datetime for the record in RFC3339 format
5+
value: Uint8Array // value to be stored in the record
6+
signature: Uint8Array // signature of the record
7+
validityType: ValidityType // Type of validation being used
8+
validity: Uint8Array // expiration datetime for the record in RFC3339 format
99
sequence: BigInt // number representing the version of the record
1010
ttl?: BigInt // ttl in nanoseconds
1111
pubKey?: Uint8Array

test/index.spec.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
'use strict'
33

44
const { expect } = require('aegir/utils/chai')
5-
const { toB58String } = require('multihashes')
5+
const { base58btc } = require('multiformats/bases/base58')
66
const uint8ArrayFromString = require('uint8arrays/from-string')
77
const PeerId = require('peer-id')
88

99
const crypto = require('libp2p-crypto')
10-
const { fromB58String } = require('multihashes')
1110

1211
const ipns = require('../src')
1312
const ERRORS = require('../src/errors')
@@ -126,14 +125,14 @@ describe('ipns', function () {
126125
})
127126

128127
it('should get datastore key correctly', () => {
129-
const datastoreKey = ipns.getLocalKey(fromB58String(ipfsId.id))
128+
const datastoreKey = ipns.getLocalKey(base58btc.decode(`z${ipfsId.id}`))
130129

131130
expect(datastoreKey).to.exist()
132131
expect(datastoreKey.toString()).to.startWith('/ipns/CIQ')
133132
})
134133

135134
it('should get id keys correctly', () => {
136-
const idKeys = ipns.getIdKeys(fromB58String(ipfsId.id))
135+
const idKeys = ipns.getIdKeys(base58btc.decode(`z${ipfsId.id}`))
137136

138137
expect(idKeys).to.exist()
139138
expect(idKeys).to.have.property('routingPubKey')
@@ -153,8 +152,8 @@ describe('ipns', function () {
153152
]
154153

155154
keys.forEach(key => {
156-
const { routingKey } = ipns.getIdKeys(fromB58String(key))
157-
const id = toB58String(routingKey.uint8Array().subarray(ipns.namespaceLength))
155+
const { routingKey } = ipns.getIdKeys(base58btc.decode(`z${key}`))
156+
const id = base58btc.encode(routingKey.uint8Array().subarray(ipns.namespaceLength)).substring(1)
158157

159158
expect(id).to.equal(key)
160159
})

0 commit comments

Comments
 (0)