-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix!: require V2 signatures #180
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
# ipns <!-- omit in toc --> | ||
|
||
[](http://ipfs.io) | ||
[](http://webchat.freenode.net/?channels=%23ipfs) | ||
[](https://ipfs.tech) | ||
[](https://discord.gg/ipfs) | ||
[](https://codecov.io/gh/ipfs/js-ipns) | ||
[](https://github.com/ipfs/js-ipns/actions/workflows/js-test-and-release.yml) | ||
|
@@ -126,7 +125,7 @@ const validator = ipns.validator | |
|
||
Contains an object with `validate (marshalledData, key)` and `select (dataA, dataB)` functions. | ||
|
||
The `validate` async function aims to verify if an IPNS record is valid. First the record is unmarshalled, then the public key is obtained and finally the record is validated (signature and validity are verified). | ||
The `validate` async function aims to verify if an IPNS record is valid. First the record is unmarshalled, then the public key is obtained and finally the record is validated (`signatureV2` of CBOR `data` is verified). | ||
|
||
The `select` function is responsible for deciding which ipns record is the best (newer) between two records. Both records are unmarshalled and their sequence numbers are compared. If the first record provided is the newer, the operation result will be `0`, otherwise the operation result will be `1`. | ||
|
||
|
@@ -151,10 +150,12 @@ Returns a `Promise` that resolves to an object with the entry's properties eg: | |
```js | ||
{ | ||
value: Uint8Array, | ||
signature: Uint8Array, | ||
signature: Uint8Array, // V1 (legacy, ignored) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. link to this PR and ipfs/js-ipfs#4207? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imo unnecessary noise for readme – is someone wants to dig, they will be able to read specs: ipfs/specs#319 |
||
validityType: 0, | ||
validity: Uint8Array, | ||
sequence: 2 | ||
sequence: 2, | ||
signatureV2: Uint8Array, // V2 signature of data field | ||
data: Uint8Array // DAG-CBOR that was signed | ||
} | ||
``` | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import errCode from 'err-code' | |
import { toString as uint8ArrayToString } from 'uint8arrays/to-string' | ||
import { equals as uint8ArrayEquals } from 'uint8arrays/equals' | ||
import { IpnsEntry } from './pb/ipns.js' | ||
import { parseRFC3339, extractPublicKey, ipnsEntryDataForV1Sig, ipnsEntryDataForV2Sig, unmarshal, peerIdFromRoutingKey, parseCborData } from './utils.js' | ||
import { parseRFC3339, extractPublicKey, ipnsEntryDataForV2Sig, unmarshal, peerIdFromRoutingKey, parseCborData } from './utils.js' | ||
import * as ERRORS from './errors.js' | ||
import type { IPNSEntry } from './index.js' | ||
import type { PublicKey } from '@libp2p/interface-keys' | ||
|
@@ -27,8 +27,7 @@ export const validate = async (publicKey: PublicKey, entry: IPNSEntry) => { | |
|
||
validateCborDataMatchesPbData(entry) | ||
} else { | ||
signature = entry.signature ?? new Uint8Array(0) | ||
dataForSignature = ipnsEntryDataForV1Sig(value, validityType, validity) | ||
throw errCode(new Error('missing data or signatureV2'), ERRORS.ERR_SIGNATURE_VERIFICATION) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe split There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the more we combine errors, and the less detail we provide, the more problems we will run into like ipfs/interop#462 where it's much harder to track down issues than it needs to be. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer to keep it simple and have single error: these fields are all-or-nothing. |
||
} | ||
|
||
// Validate Signature | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of making this change here, can you please PR these lines then running
npx aegir check-project
in the root of this repo will update the badges, etc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done: ipfs/aegir#1073