New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ensdomains/content-hash

Package Overview
Dependencies
Maintainers
4
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ensdomains/content-hash - npm Package Compare versions

Comparing version 2.5.5 to 2.5.6

7

package.json
{
"name": "@ensdomains/content-hash",
"version": "2.5.5",
"version": "2.5.6",
"description": "simple tool to encode/decode content hash for EIP 1577 compliant ENS Resolvers (fork of pldespaigne/content-hash)",

@@ -21,4 +21,5 @@ "main": "./src/index.js",

"dependencies": {
"cids": "^0.8.3",
"multicodec": "^1.0.4",
"cids": "^1.1.5",
"js-base64": "^3.6.0",
"multicodec": "^2.1.0",
"multihashes": "^2.0.0"

@@ -25,0 +26,0 @@ },

@@ -20,2 +20,3 @@ /*

const multiC = require('multicodec');
const multiH = require('multihashes');

@@ -57,2 +58,11 @@ const { hexStringToBuffer, profiles } = require('./profiles');

/**
* Encode a Skylink into a content hash
* @param {string} skylink string containing a Skylink
* @return {string} the resulting content hash
*/
fromSkylink: function (skylink) {
return this.encode('skynet-ns', skylink);
},
/**
* Encode a Swarm address into a content hash

@@ -75,3 +85,3 @@ * @param {string} swarmHash string containing a Swarm address

const encodedValue = profile.encode(value);
return multiC.addPrefix(codec, encodedValue).toString('hex');
return multiH.toHexString(multiC.addPrefix(codec, encodedValue))
},

@@ -78,0 +88,0 @@

@@ -21,2 +21,3 @@ /*

const multiH = require('multihashes');
const base64 = require('js-base64')

@@ -74,5 +75,12 @@ /**

*/
skynet: (value) => {
return base64.toUint8Array(value)
},
/**
* @param {string} value
* @return {Buffer}
*/
swarm: (value) => {
const multihash = multiH.encode(hexStringToBuffer(value), 'keccak-256');
return new CID(1, 'swarm-manifest', multihash).buffer;
return new CID(1, 'swarm-manifest', multihash).bytes;
},

@@ -84,3 +92,3 @@ /**

ipfs: (value) => {
return new CID(value).toV1().buffer;
return new CID(value).toV1().bytes;
},

@@ -98,3 +106,3 @@ /**

// https://github.com/libp2p/specs/blob/master/RFC/0001-text-peerid-cid.md
return new CID(1, 'libp2p-key', cid.multihash).buffer
return new CID(1, 'libp2p-key', cid.multihash).bytes
},

@@ -150,2 +158,6 @@ /**

},
base64: (value) => {
// `true` option makes it URL safe (replaces / and + with - and _ )
return base64.fromUint8Array(value, true)
}
};

@@ -159,2 +171,6 @@

const profiles = {
'skynet-ns': {
encode: encodes.skynet,
decode: decodes.base64,
},
'swarm-ns': {

@@ -161,0 +177,0 @@ encode: encodes.swarm,

@@ -22,2 +22,4 @@

const ipfsBase32Libp2pKey = 'bafzbeie5745rpv2m6tjyuugywy4d5ewrqgqqhfnf445he3omzpjbx5xqxe';
const skylink = 'CABAB_1Dt0FJsxqsu_J4TodNCbCGvtFf1Uys_3EgzOlTcg'
const skylink_contentHash = '90b2c60508004007fd43b74149b31aacbbf2784e874d09b086bed15fd54cacff7120cce95372'

@@ -128,11 +130,11 @@ describe('content-hash (legacy tests)', () =>

});
it('should decode deprecated DNSLink identifiers', () => {
// DNSLink is fine to be used before ENS resolve occurs, but should be avoided after
// Context: https://github.com/ensdomains/ens-app/issues/849#issuecomment-777088950
// For now, we allow decoding of legacy values:
const deprecated_dnslink_contentHash = 'e5010170000f6170702e756e69737761702e6f7267'
const deprecated_dnslink_value = 'app.uniswap.org'
const actual = contentHash.decode(deprecated_dnslink_contentHash)
actual.should.be.equal(deprecated_dnslink_value)
});
it('should decode deprecated DNSLink identifiers', () => {
// DNSLink is fine to be used before ENS resolve occurs, but should be avoided after
// Context: https://github.com/ensdomains/ens-app/issues/849#issuecomment-777088950
// For now, we allow decoding of legacy values:
const deprecated_dnslink_contentHash = 'e5010170000f6170702e756e69737761702e6f7267'
const deprecated_dnslink_value = 'app.uniswap.org'
const actual = contentHash.decode(deprecated_dnslink_contentHash)
actual.should.be.equal(deprecated_dnslink_value)
});
});

@@ -167,2 +169,18 @@ describe('onion', () => {

});
describe('skynet', () => {
it('should encode', () => {
const actual = contentHash.encode('skynet-ns', skylink);
actual.should.be.equal(skylink_contentHash);
});
it('should getCodec', () => {
const actual = contentHash.getCodec(skylink_contentHash);
actual.should.be.equal('skynet-ns');
});
it('should decode', () => {
const actual = contentHash.decode(skylink_contentHash);
actual.should.be.equal(skylink);
});
});
describe('helpers.cidV0ToV1Base32', () => {

@@ -181,2 +199,3 @@ const { cidV0ToV1Base32 } = contentHash.helpers;

});
describe('helpers.cidForWeb', () => {

@@ -183,0 +202,0 @@ const { cidForWeb } = contentHash.helpers;

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc