ipfs / js-ipns

Utilities for creating, parsing, and validating IPNS records
Other
80 stars 24 forks source link

bug: nanoseconds #310

Closed SgtPooki closed 3 months ago

SgtPooki commented 3 months ago

Nanoseconds are calculated incorrectly. See https://github.com/ipfs/helia-verified-fetch/pull/19#discussion_r1530216696 for more details. Basically,

Some proofs (copy and paste into dev console):

https://github.com/ipfs/js-ipns/blob/16e0e10682fa9a663e0bb493a44d3e99a5200944/src/index.ts#L171 creates lifeTimeNs as:

function lifeTimeNs(ms, ns) {
    // BigInt(100000) === BigInt(1e5)
    return (BigInt(ms) * BigInt(100000)) + BigInt(ns ?? '0')
}
// should match BigInt(1)/*<ms>*/ * BigInt(1e6)/*<ns>*/ === 1000000n/*<ns>*/
lifeTimeNs(1) === BigInt(1e6) // false, 
// returns `100000n` instead of `1000000n`

references:

welcome[bot] commented 3 months ago

Thank you for submitting your first issue to this repository! A maintainer will be here shortly to triage and review. In the meantime, please double-check that you have provided all the necessary information to make this process easy! Any information that can help save additional round trips is useful! We currently aim to give initial feedback within two business days. If this does not happen, feel free to leave a comment. Please keep an eye on how this issue will be labeled, as labels give an overview of priorities, assignments and additional actions requested by the maintainers:

Finally, remember to use https://discuss.ipfs.io if you just need general support.