Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
"@libp2p/crypto": "^5.0.0",
"@libp2p/interface": "^3.0.2",
"@libp2p/logger": "^6.0.4",
"cborg": "^5.1.0",
"cborg": "^6.1.1",
"interface-datastore": "^10.0.0",
"multiformats": "^14.0.0",
"protons-runtime": "^7.0.0",
Expand Down
1 change: 0 additions & 1 deletion src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export async function ipnsValidator (routingKey: Uint8Array, marshalledRecord: U
throw new InvalidEmbeddedPublicKeyError('Could not extract public key from IPNS record or routing key')
}

// @ts-expect-error @libp2p/crypto needs a new multiformats
const expectedRoutingKey = multihashToIPNSRoutingKey(recordPubKey.toMultihash())

if (!uint8ArrayEquals(expectedRoutingKey, routingKey)) {
Expand Down
13 changes: 0 additions & 13 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ describe('ipns', function () {
const record = await createIPNSRecordWithExpiration(privateKey, contentPath, sequence, expiration)
const marshalledRecord = marshalIPNSRecord(record)

// @ts-expect-error @libp2p/crypto needs a new multiformats
await ipnsValidator(multihashToIPNSRoutingKey(privateKey.publicKey.toMultihash()), marshalledRecord)

const pb = IpnsEntry.decode(marshalledRecord)
Expand All @@ -121,7 +120,6 @@ describe('ipns', function () {
const record = await createIPNSRecordWithExpiration(privateKey, contentPath, sequence, expiration, { v1Compatible: false })
const marshalledRecord = marshalIPNSRecord(record)

// @ts-expect-error @libp2p/crypto needs a new multiformats
await ipnsValidator(multihashToIPNSRoutingKey(privateKey.publicKey.toMultihash()), marshalledRecord)

const pb = IpnsEntry.decode(marshalIPNSRecord(record))
Expand All @@ -141,7 +139,6 @@ describe('ipns', function () {
})
const marshalledRecord = marshalIPNSRecord(record)

// @ts-expect-error @libp2p/crypto needs a new multiformats
await ipnsValidator(multihashToIPNSRoutingKey(privateKey.publicKey.toMultihash()), marshalledRecord)

const pb = IpnsEntry.decode(marshalledRecord)
Expand All @@ -160,7 +157,6 @@ describe('ipns', function () {
})
const marshalledRecord = marshalIPNSRecord(record)

// @ts-expect-error @libp2p/crypto needs a new multiformats
await ipnsValidator(multihashToIPNSRoutingKey(privateKey.publicKey.toMultihash()), marshalledRecord)

const pb = IpnsEntry.decode(marshalledRecord)
Expand All @@ -175,7 +171,6 @@ describe('ipns', function () {
const validity = 1000000

const record = await createIPNSRecord(privateKey, contentPath, sequence, validity)
// @ts-expect-error @libp2p/crypto needs a new multiformats
await ipnsValidator(multihashToIPNSRoutingKey(privateKey.publicKey.toMultihash()), marshalIPNSRecord(record))
})

Expand All @@ -184,7 +179,6 @@ describe('ipns', function () {
const validity = 1000000

const record = await createIPNSRecord(privateKey, contentPath, sequence, validity, { v1Compatible: false })
// @ts-expect-error @libp2p/crypto needs a new multiformats
await ipnsValidator(multihashToIPNSRoutingKey(privateKey.publicKey.toMultihash()), marshalIPNSRecord(record))
})

Expand Down Expand Up @@ -213,7 +207,6 @@ describe('ipns', function () {
const otherKey = await generateKeyPair('Ed25519')
const peerId = peerIdFromPrivateKey(otherKey)
const expectedValue = `/ipns/${peerId.toCID().toString(base36)}`
// @ts-expect-error @libp2p/crypto needs a new multiformats
const record = await createIPNSRecord(privateKey, peerId.toCID(), 0, 1000000)
expect(record.value).to.equal(expectedValue)
})
Expand Down Expand Up @@ -286,7 +279,6 @@ describe('ipns', function () {
// confirm a v1 exists
expect(pb).to.have.property('signatureV1')

// @ts-expect-error @libp2p/crypto needs a new multiformats
await expect(ipnsValidator(multihashToIPNSRoutingKey(privateKey.publicKey.toMultihash()), IpnsEntry.encode(pb))).to.eventually.be.rejected()
.with.property('name', SignatureVerificationError.name)
})
Expand All @@ -304,7 +296,6 @@ describe('ipns', function () {
// confirm a v1 exists
expect(pb).to.have.property('signatureV1')

// @ts-expect-error @libp2p/crypto needs a new multiformats
await expect(ipnsValidator(multihashToIPNSRoutingKey(privateKey.publicKey.toMultihash()), IpnsEntry.encode(pb))).to.eventually.be.rejected()
.with.property('name', SignatureVerificationError.name)
})
Expand All @@ -318,7 +309,6 @@ describe('ipns', function () {
// corrupt the record by changing the value to random bytes
record.value = uint8ArrayToString(randomBytes(46))

// @ts-expect-error @libp2p/crypto needs a new multiformats
await expect(ipnsValidator(multihashToIPNSRoutingKey(privateKey.publicKey.toMultihash()), marshalIPNSRecord(record))).to.eventually.be.rejected()
.with.property('name', SignatureVerificationError.name)
})
Expand All @@ -331,7 +321,6 @@ describe('ipns', function () {

await new Promise(resolve => setTimeout(resolve, 1))

// @ts-expect-error @libp2p/crypto needs a new multiformats
await expect(ipnsValidator(multihashToIPNSRoutingKey(privateKey.publicKey.toMultihash()), marshalIPNSRecord(record))).to.eventually.be.rejected()
.with.property('name', RecordExpiredError.name)
})
Expand All @@ -354,7 +343,6 @@ describe('ipns', function () {
expect(createdRecord.signatureV2).to.equalBytes(unmarshalledData.signatureV2)
expect(createdRecord.data).to.equalBytes(unmarshalledData.data)

// @ts-expect-error @libp2p/crypto needs a new multiformats
await ipnsValidator(multihashToIPNSRoutingKey(privateKey.publicKey.toMultihash()), marshalledData)
})

Expand Down Expand Up @@ -409,7 +397,6 @@ describe('ipns', function () {
delete record.pubKey

const marshalledData = marshalIPNSRecord(record)
// @ts-expect-error @libp2p/crypto needs a new multiformats
const key = multihashToIPNSRoutingKey(privateKey.publicKey.toMultihash())

await expect(ipnsValidator(key, marshalledData)).to.eventually.be.rejected()
Expand Down
2 changes: 0 additions & 2 deletions test/selector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ describe('selector', function () {
const marshalledData = marshalIPNSRecord(record)
const marshalledNewData = marshalIPNSRecord(newRecord)

// @ts-expect-error @libp2p/crypto needs a new multiformats
const key = multihashToIPNSRoutingKey(privateKey.publicKey.toMultihash())

let valid = ipnsSelector(key, [marshalledNewData, marshalledData])
Expand All @@ -44,7 +43,6 @@ describe('selector', function () {
const marshalledData = marshalIPNSRecord(record)
const marshalledNewData = marshalIPNSRecord(newRecord)

// @ts-expect-error @libp2p/crypto needs a new multiformats
const key = multihashToIPNSRoutingKey(privateKey.publicKey.toMultihash())

let valid = ipnsSelector(key, [marshalledNewData, marshalledData])
Expand Down
1 change: 0 additions & 1 deletion test/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ describe('utils', () => {

Object.entries(cases).forEach(([name, input]) => {
it(`should round trip a ${name} key`, async () => {
// @ts-expect-error @libp2p/crypto needs a new multiformats
const key = multihashToIPNSRoutingKey(input.toMultihash())
const output = multihashFromIPNSRoutingKey(key)

Expand Down
5 changes: 0 additions & 5 deletions test/validator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ describe('validator', function () {
const validity = 1000000
const record = await createIPNSRecord(privateKey1, contentPath, sequence, validity, { v1Compatible: false })
const marshalledData = marshalIPNSRecord(record)
// @ts-expect-error @libp2p/crypto needs a new multiformats
const key = multihashToIPNSRoutingKey(privateKey1.publicKey.toMultihash())

await ipnsValidator(key, marshalledData)
Expand All @@ -35,7 +34,6 @@ describe('validator', function () {
const validity = 1000000
const record = await createIPNSRecord(privateKey1, contentPath, sequence, validity, { v1Compatible: true })
const marshalledData = marshalIPNSRecord(record)
// @ts-expect-error @libp2p/crypto needs a new multiformats
const key = multihashToIPNSRoutingKey(privateKey1.publicKey.toMultihash())

await ipnsValidator(key, marshalledData)
Expand All @@ -51,7 +49,6 @@ describe('validator', function () {
record.value = uint8ArrayToString(randomBytes(record.value?.length ?? 0))
const marshalledData = marshalIPNSRecord(record)

// @ts-expect-error @libp2p/crypto needs a new multiformats
const key = multihashToIPNSRoutingKey(privateKey1.publicKey.toMultihash())

await expect(ipnsValidator(key, marshalledData)).to.eventually.be.rejected()
Expand All @@ -65,7 +62,6 @@ describe('validator', function () {
const record = await createIPNSRecord(privateKey1, contentPath, sequence, validity)
const marshalledData = marshalIPNSRecord(record)

// @ts-expect-error @libp2p/crypto needs a new multiformats
const key = multihashToIPNSRoutingKey(privateKey2.publicKey.toMultihash())

await expect(ipnsValidator(key, marshalledData)).to.eventually.be.rejected()
Expand All @@ -80,7 +76,6 @@ describe('validator', function () {
record.pubKey = publicKeyToProtobuf(privateKey2.publicKey)
const marshalledData = marshalIPNSRecord(record)

// @ts-expect-error @libp2p/crypto needs a new multiformats
const key = multihashToIPNSRoutingKey(privateKey1.publicKey.toMultihash())

await expect(ipnsValidator(key, marshalledData)).to.eventually.be.rejected()
Expand Down
Loading