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

bitski-provider

Package Overview
Dependencies
Maintainers
3
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitski-provider - npm Package Compare versions

Comparing version 0.10.2 to 0.10.4

13

dist/subproviders/typed-data.js

@@ -90,7 +90,7 @@ import { Subprovider } from '@bitski/provider-engine';

const baseType = type.split('[')[0];
if (typeof values[key].length === 'undefined') {
throw new TypeError(`Could not parse ${values[key]} for type ${type}. Expected array.`);
}
// If base type is a struct, iterate through each instance of struct
if (typeMapping[baseType]) {
if (typeof values[key].length === 'undefined') {
throw new TypeError(`Could not parse ${values[key]} for type ${type}. Expected array.`);
}
// values[key] is expected to be an array, where each element

@@ -102,2 +102,9 @@ // is an object that represents the struct named baseType.

}
else if (baseType.startsWith('uint') || baseType.startsWith('int')) {
// If we have an array of primitive types that are numbers, we need to encode the numbers as hex
const numberValues = values[key].map((numberValue) => {
return encodeNumber(numberValue, baseType, true);
});
values[key] = numberValues;
}
else {

@@ -104,0 +111,0 @@ // Do nothing with regular array values

@@ -14,4 +14,4 @@ import BN from 'bn.js';

if (type === 'string') {
if (type.substr(0, 2) === '0x') {
return new BN(type.substr(2), 16);
if (arg.substr(0, 2) === '0x') {
return new BN(arg.substr(2), 16);
}

@@ -18,0 +18,0 @@ else {

@@ -104,7 +104,7 @@ (function (factory) {

const baseType = type.split('[')[0];
if (typeof values[key].length === 'undefined') {
throw new TypeError(`Could not parse ${values[key]} for type ${type}. Expected array.`);
}
// If base type is a struct, iterate through each instance of struct
if (typeMapping[baseType]) {
if (typeof values[key].length === 'undefined') {
throw new TypeError(`Could not parse ${values[key]} for type ${type}. Expected array.`);
}
// values[key] is expected to be an array, where each element

@@ -116,2 +116,9 @@ // is an object that represents the struct named baseType.

}
else if (baseType.startsWith('uint') || baseType.startsWith('int')) {
// If we have an array of primitive types that are numbers, we need to encode the numbers as hex
const numberValues = values[key].map((numberValue) => {
return parse_utils_1.encodeNumber(numberValue, baseType, true);
});
values[key] = numberValues;
}
else {

@@ -118,0 +125,0 @@ // Do nothing with regular array values

@@ -28,4 +28,4 @@ var __importDefault = (this && this.__importDefault) || function (mod) {

if (type === 'string') {
if (type.substr(0, 2) === '0x') {
return new bn_js_1.default(type.substr(2), 16);
if (arg.substr(0, 2) === '0x') {
return new bn_js_1.default(arg.substr(2), 16);
}

@@ -32,0 +32,0 @@ else {

@@ -12,3 +12,3 @@ {

},
"version": "0.10.2",
"version": "0.10.4",
"scripts": {

@@ -29,3 +29,3 @@ "test": "jest",

},
"gitHead": "3af07cfa8c2a6d78eaa360c3624d3611d882f4bd"
"gitHead": "0a072902f0dc86249cf82bb4a00300fca897a2d8"
}

@@ -123,7 +123,7 @@ import { Subprovider } from '@bitski/provider-engine';

const baseType = type.split('[')[0];
if (typeof values[key].length === 'undefined') {
throw new TypeError(`Could not parse ${values[key]} for type ${type}. Expected array.`);
}
// If base type is a struct, iterate through each instance of struct
if (typeMapping[baseType]) {
if (typeof values[key].length === 'undefined') {
throw new TypeError(`Could not parse ${values[key]} for type ${type}. Expected array.`);
}
// values[key] is expected to be an array, where each element

@@ -134,2 +134,8 @@ // is an object that represents the struct named baseType.

});
} else if (baseType.startsWith('uint') || baseType.startsWith('int')) {
// If we have an array of primitive types that are numbers, we need to encode the numbers as hex
const numberValues = values[key].map((numberValue) => {
return encodeNumber(numberValue, baseType, true);
});
values[key] = numberValues;
} else {

@@ -136,0 +142,0 @@ // Do nothing with regular array values

@@ -15,4 +15,4 @@ import BN from 'bn.js';

if (type === 'string') {
if (type.substr(0, 2) === '0x') {
return new BN(type.substr(2), 16);
if (arg.substr(0, 2) === '0x') {
return new BN(arg.substr(2), 16);
} else {

@@ -19,0 +19,0 @@ return new BN(arg, 10);

@@ -302,2 +302,34 @@ import { ProviderError, ProviderErrorCode } from '../src/errors/provider-error';

test('it sanitizes arrays of numbers', () => {
expect(3);
const typedData = {
types: {
EIP712Domain: [
{ name: 'name', type: 'string' },
{ name: 'chainId', type: 'uint256' },
],
TestStruct: [
{ name: 'title', type: 'string' },
{ name: 'values', type: 'uint256[]' },
],
},
domain: {
name: 'Test Domain',
chainId: 1,
},
primaryType: 'TestStruct',
message: {
title: 'Hello World',
values: ['1000', 200, '0x0'],
},
};
const mapping = createTypeMapping(typedData);
sanitizeMessage(typedData, mapping);
expect(typedData.message.values[0]).toBe('0x3e8');
expect(typedData.message.values[1]).toBe('0xc8');
expect(typedData.message.values[2]).toBe('0x0');
expect(typedData.message.title).toBe('Hello World');
});
test('it throws errors when sanitizing bad data', () => {

@@ -304,0 +336,0 @@ expect.assertions(4);

Sorry, the diff of this file is not supported yet

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