How to use the ipns.create function in ipns

To help you get started, we’ve selected a few ipns examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ipfs / js-ipfs / src / core / ipns / publisher.js View on Github external
throw errcode(new Error(errMsg), 'ERR_DETERMINING_PUBLISHED_RECORD')
      }
    }

    // Determinate the record sequence number
    let seqNumber = 0

    if (record && record.sequence !== undefined) {
      seqNumber = record.value.toString() !== value ? record.sequence + 1 : record.sequence
    }

    let entryData

    try {
      // Create record
      entryData = await ipns.create(privKey, value, seqNumber, validity)
    } catch (err) {
      const errMsg = `ipns record for ${value} could not be created`

      log.error(err)
      throw errcode(new Error(errMsg), 'ERR_CREATING_IPNS_RECORD')
    }

    // TODO IMPROVEMENT - set ttl (still experimental feature for go)

    try {
      // Marshal record
      const data = ipns.marshal(entryData)

      // Store the new record
      await this._datastore.put(ipns.getLocalKey(peerId.id), data)