Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
ipns record definitions
This module contains all the necessary code for creating, understanding and validating IPNS records.
npm install ipns
import * as ipns from 'ipns'
const entryData = await ipns.create(privateKey, value, sequenceNumber, lifetime)
import * as ipns from 'ipns'
await ipns.validate(publicKey, ipnsEntry)
// if no error thrown, the record is valid
import * as ipns from 'ipns'
const ipnsEntryWithEmbedPublicKey = await ipns.embedPublicKey(publicKey, ipnsEntry)
import * as ipns from 'ipns'
const publicKey = ipns.extractPublicKey(peerId, ipnsEntry)
import * as ipns from 'ipns'
ipns.getLocalKey(peerId)
Returns a key to be used for storing the ipns entry locally, that is:
/ipns/${base32(<HASH>)}
import * as ipns from 'ipns'
const entryData = await ipns.create(privateKey, value, sequenceNumber, lifetime)
// ...
const marshalledData = ipns.marshal(entryData)
// ...
Returns the entry data serialized.
import * as ipns from 'ipns'
const data = ipns.unmarshal(storedData)
Returns the entry data structure after being serialized.
import * as ipns from 'ipns'
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 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
.
ipns.create(privateKey, value, sequenceNumber, lifetime)
Create an IPNS record for being stored in a protocol buffer.
privateKey
(PrivKey
RSA Instance): key to be used for cryptographic operations.value
(Uint8Array): ipfs path of the object to be published.sequenceNumber
(Number): number representing the current version of the record.lifetime
(Number): lifetime of the record (in milliseconds).Returns a Promise
that resolves to an object with the entry's properties eg:
{
value: Uint8Array,
signature: Uint8Array,
validityType: 0,
validity: Uint8Array,
sequence: 2
}
ipns.validate(publicKey, ipnsEntry)
Validate an IPNS record previously stored in a protocol buffer.
publicKey
(PubKey
RSA Instance): key to be used for cryptographic operations.ipnsEntry
(Object): ipns entry record (obtained using the create function).Returns a Promise
, which may be rejected if the validation was not successful.
ipns.getDatastoreKey(peerId)
Get a key for storing the ipns entry in the datastore.
peerId
(Uint8Array
): peer identifier.const marshalledData = ipns.marshal(entryData)
Returns the entry data serialized.
entryData
(Object): ipns entry record (obtained using the create function).const data = ipns.unmarshal(storedData)
Returns the entry data structure after being serialized.
storedData
(Uint8Array): ipns entry record serialized.const recordWithPublicKey = await ipns.embedPublicKey(publicKey, ipnsEntry)
Embed a public key in an IPNS entry. If it is possible to extract the public key from the peer-id
, there is no need to embed.
publicKey
(PubKey
RSA Instance): key to be used for cryptographic operations.ipnsEntry
(Object): ipns entry record (obtained using the create function).Returns a Promise
. If the promise resolves to null it means the public key can be extracted directly from the peer-id
.
ipns.extractPublicKey(peerId, ipnsEntry, [callback])
Extract a public key from an IPNS entry.
peerId
(PeerId
Instance): peer identifier object.ipnsEntry
(Object): ipns entry record (obtained using the create function).The returned public key (PubKey
RSA Instance): may be used for cryptographic operations.
Namespace constants for records.
ipns.namespace
// '/ipns/'
ipns.namespaceLength
// 6
Feel free to join in. All welcome. Open an issue!
This repository falls under the IPFS Code of Conduct.
Copyright (c) Protocol Labs, Inc. under the MIT License. See LICENSE file for details.
FAQs
IPNS record definitions
The npm package ipns receives a total of 10,264 weekly downloads. As such, ipns popularity was classified as popular.
We found that ipns demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.