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

iota-tangle

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iota-tangle - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

dist/hash.d.ts

4

dist/factory.d.ts
/// <reference types="node" />
import { Transaction } from './transaction';
import { Hash } from './hash';
import { Serializer } from './serializer';

@@ -10,3 +11,4 @@ export interface FactoryParams {

constructor(params: FactoryParams);
createTransactionFromBytes(buffer: Buffer): Transaction;
createTransactionFromBytes(bytes: Buffer): Transaction;
createHashFromBytes(bytes: Buffer): Hash;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const transaction_1 = require("./transaction");
const hash_1 = require("./hash");
class Factory {

@@ -8,6 +9,9 @@ constructor(params) {

}
createTransactionFromBytes(buffer) {
return transaction_1.Transaction.createFromBytes(this._serializer, buffer);
createTransactionFromBytes(bytes) {
return transaction_1.Transaction.createFromBytes(bytes, this._serializer);
}
createHashFromBytes(bytes) {
return hash_1.Hash.createFromBytes(bytes);
}
}
exports.Factory = Factory;

@@ -5,3 +5,3 @@ /// <reference types="node" />

static BYTES_SIZE: number;
static createFromBytes(serializer: Serializer, bytes: Buffer): Transaction;
static createFromBytes(bytes: Buffer, serializer: Serializer): Transaction;
private _serializer;

@@ -8,0 +8,0 @@ private _bytes;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Transaction {
static createFromBytes(serializer, bytes) {
static createFromBytes(bytes, serializer) {
if (bytes.byteLength !== Transaction.BYTES_SIZE) {
throw new Error('Incorrecty bytes size!');
throw new Error('Bytes size is incorrect!');
}

@@ -8,0 +8,0 @@ const transaction = new Transaction();

{
"name": "iota-tangle",
"version": "0.0.2",
"version": "0.0.3",
"description": "Basic models and services for IOTA's tangle",
"main": "./dist/index.ts",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",

@@ -7,0 +7,0 @@ "scripts": {

import { Transaction } from './transaction'
import { Hash } from './hash'
import { Serializer } from './serializer'

@@ -16,5 +17,9 @@

createTransactionFromBytes(buffer: Buffer) {
return Transaction.createFromBytes(this._serializer, buffer)
createTransactionFromBytes(bytes: Buffer): Transaction {
return Transaction.createFromBytes(bytes, this._serializer)
}
createHashFromBytes(bytes: Buffer): Hash {
return Hash.createFromBytes(bytes)
}
}

@@ -7,5 +7,5 @@ import { Serializer } from './serializer'

static createFromBytes(serializer: Serializer, bytes: Buffer) {
static createFromBytes(bytes: Buffer, serializer: Serializer): Transaction {
if (bytes.byteLength !== Transaction.BYTES_SIZE) {
throw new Error('Incorrecty bytes size!')
throw new Error('Bytes size is incorrect!')
}

@@ -12,0 +12,0 @@

@@ -6,2 +6,3 @@ import { expect } from 'chai'

import { Transaction } from '../src/transaction'
import { Hash } from '../src/hash'

@@ -17,3 +18,3 @@ describe('Factory', () => {

describe('::createFromBytes(buffer)', () => {
describe('createTransactionFromBytes(bytes)', () => {
let transactionBytes: Buffer

@@ -29,6 +30,6 @@

expect(transaction).to.be.an.instanceOf(Transaction)
expect(transaction.bytes.equals(transactionBytes)).to.be.true
expect(transaction.bytes).to.be.equal(transactionBytes)
})
it('should throw an error if bytes size is too low or too big', () => {
it('should throw an error if bytes size is too low or too high', () => {
expect(() => {

@@ -43,2 +44,28 @@ factory.createTransactionFromBytes(transactionBytes.slice(0, Transaction.BYTES_SIZE - 10))

})
describe('createHashFromBytes(bytes)', () => {
let hashBytes: Buffer
beforeEach(() => {
hashBytes = Buffer.alloc(49)
})
it('should create a hash object', () => {
const hash = factory.createHashFromBytes(hashBytes)
expect(hash).to.be.an.instanceOf(Hash)
expect(hash.bytes).to.be.equal(hashBytes)
})
it('should throw and error if bytes size is too low or too high', () => {
expect(() => {
factory.createHashFromBytes(hashBytes.slice(0, Hash.BYTES_SIZE - 10))
}).to.throw()
expect(() => {
factory.createHashFromBytes(Buffer.concat([hashBytes, new Buffer('12341234', 'utf8')]))
}).to.throw()
})
})
})
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