Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@emurgo/cip14-js

Package Overview
Dependencies
Maintainers
3
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@emurgo/cip14-js - npm Package Compare versions

Comparing version 1.0.2 to 2.0.0

11

index.d.ts

@@ -1,1 +0,10 @@

export declare function assetFingerprint(policyId: Uint8Array, assetName: Uint8Array): string;
/// <reference types="node" />
export default class assetFingerprint {
hashBuf: Uint8Array;
constructor(policyId?: Uint8Array, assetName?: Uint8Array);
fromHash(hash: Buffer): this;
fromBech32(fingerprint: string): this;
fingerprint(): string;
hash(): string;
prefix(): string;
}

@@ -6,12 +6,36 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.assetFingerprint = void 0;
const blake2b_1 = __importDefault(require("blake2b"));
const bech32_1 = require("bech32");
/// note: this function can't be inverted due to the hash
function assetFingerprint(policyId, assetName) {
// see https://github.com/cardano-foundation/CIPs/pull/64
const datapart = blake2b_1.default(20).update(new Uint8Array([...policyId, ...assetName])).digest('binary');
const words = bech32_1.bech32.toWords(datapart);
return bech32_1.bech32.encode('asset', words);
const DATA = "asset";
class assetFingerprint {
constructor(policyId = new Uint8Array(32), assetName = new Uint8Array(0)) {
// see https://github.com/cardano-foundation/CIPs/pull/64
this.hashBuf = blake2b_1.default(20)
.update(new Uint8Array([...policyId, ...assetName]))
.digest("binary");
}
fromHash(hash) {
this.hashBuf = hash;
return this;
}
fromBech32(fingerprint) {
const { prefix, words } = bech32_1.bech32.decode(fingerprint);
if (prefix !== DATA) {
throw new Error("Invalid asset fingerprint");
}
this.hashBuf = Buffer.from(bech32_1.bech32.fromWords(words));
return this;
}
fingerprint() {
const words = bech32_1.bech32.toWords(this.hashBuf);
return bech32_1.bech32.encode(DATA, words);
}
hash() {
return Buffer.from(this.hashBuf).toString('hex');
}
prefix() {
return DATA;
}
}
exports.assetFingerprint = assetFingerprint;
exports.default = assetFingerprint;

4

package.json
{
"name": "@emurgo/cip14-js",
"version": "1.0.2",
"version": "2.0.0",
"description": "A Javascript library reference implementation for CIP14",

@@ -22,3 +22,3 @@ "main": "./index.js",

},
"license": "Apache-2.0",
"license": "Apache-2.0 OR MIT",
"repository": {

@@ -25,0 +25,0 @@ "type": "git",

@@ -8,1 +8,27 @@ # CIP14-JS

This package is a Typescript implementation of CIP14
## Install
``` sh
npm i @emurgo/cip14-js --save
```
## Usage
```js
const AssetFingerprint = require('@emurgo/cip14-js');
// initialize class with policyId, assetName
const assetFingerprint = new AssetFingerprint(Buffer.from('1e349c9bdea19fd6c147626a5260bc44b71635f398b67c59881df209', 'hex'), Buffer.from('504154415445', 'hex'));
const fingerprintHash = assetFingerprint.hash();
const bech32Fingerprint = assetFingerprint.fingerprint();
```
```js
// initialize class with bech32
const assetFingerprint = new AssetFingerprint().fromBech32('asset1rjklcrnsdzqp65wjgrg55sy9723kw09mlgvlc3');
const fingerprintHash = assetFingerprint.hash();
const prefix = assetFingerprint.prefix();
```

Sorry, the diff of this file is not supported yet

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