Socket
Socket
Sign inDemoInstall

@celo/utils

Package Overview
Dependencies
Maintainers
18
Versions
144
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@celo/utils - npm Package Compare versions

Comparing version 1.5.2 to 2.0.0-alpha1

9

lib/commentEncryption.test.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var crypto_1 = require("crypto");
var elliptic_1 = require("elliptic");
var commentEncryption_1 = require("./commentEncryption");
var ec = new elliptic_1.ec('secp256k1');
describe('Comment Encryption', function () {
// NOTE: elliptic is disabled elsewhere in this library to prevent
// accidental signing of truncated messages.
// tslint:disable-next-line:import-blacklist
var EC = require('elliptic').ec;
var ec = new EC('secp256k1');
var self = ec.keyFromPrivate((0, crypto_1.randomBytes)(32));

@@ -83,3 +86,3 @@ var selfPublic = Buffer.from(self.getPublic('hex'), 'hex');

// How comment was encrypted.
// Uses elliptic package
// Uses elliptic package (see note above)
// console.info(

@@ -86,0 +89,0 @@ // encryptComment(

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DataEncryptionKeyUtils = exports.deriveDek = exports.decompressPublicKey = exports.compressedPubKey = void 0;
var elliptic_1 = require("elliptic");
var account_1 = require("./account");
var address_1 = require("./address");
var ec = new elliptic_1.ec('secp256k1');
/**

@@ -15,2 +13,7 @@ * Turns a private key to a compressed public key (hex string with hex leader).

function compressedPubKey(privateKey) {
// NOTE: elliptic is disabled elsewhere in this library to prevent
// accidental signing of truncated messages.
// tslint:disable-next-line:import-blacklist
var EC = require('elliptic').ec;
var ec = new EC('secp256k1');
var key = ec.keyFromPrivate(privateKey);

@@ -28,2 +31,7 @@ return (0, address_1.ensureLeading0x)(key.getPublic(true, 'hex'));

function decompressPublicKey(publicKey) {
// NOTE: elliptic is disabled elsewhere in this library to prevent
// accidental signing of truncated messages.
// tslint:disable-next-line:import-blacklist
var EC = require('elliptic').ec;
var ec = new EC('secp256k1');
return Buffer.from(ec.keyFromPublic(publicKey).getPublic(false, 'hex'), 'hex').slice(1);

@@ -30,0 +38,0 @@ }

@@ -40,5 +40,3 @@ "use strict";

var crypto_1 = require("crypto");
var elliptic_1 = require("elliptic");
var dataEncryptionKey_1 = require("./dataEncryptionKey");
var ec = new elliptic_1.ec('secp256k1');
describe('deriveDek', function () {

@@ -63,2 +61,7 @@ it('should produce a the expected keys', function () { return __awaiter(void 0, void 0, void 0, function () {

it('should work with compressed input', function () {
// NOTE: elliptic is disabled elsewhere in this library to prevent
// accidental signing of truncated messages.
// tslint:disable-next-line:import-blacklist
var EC = require('elliptic').ec;
var ec = new EC('secp256k1');
var privateKey = ec.keyFromPrivate((0, crypto_1.randomBytes)(32));

@@ -72,2 +75,7 @@ var publicKeyFull = Buffer.from(privateKey.getPublic(false, 'hex'), 'hex');

it('should work with long form input', function () {
// NOTE: elliptic is disabled elsewhere in this library to prevent
// accidental signing of truncated messages.
// tslint:disable-next-line:import-blacklist
var EC = require('elliptic').ec;
var ec = new EC('secp256k1');
var privateKey = ec.keyFromPrivate((0, crypto_1.randomBytes)(32));

@@ -74,0 +82,0 @@ var publicKeyFull = Buffer.from(privateKey.getPublic(false, 'hex'), 'hex');

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

export declare function ensureCompressed(publicKey: string): string;
export declare function ensureUncompressed(publicKey: string): string;
export declare function ensureUncompressed(publicKey: string): any;
export declare function trimUncompressedPrefix(publicKey: string): string;

@@ -6,4 +6,2 @@ "use strict";

var crypto_1 = require("crypto");
var elliptic_1 = require("elliptic");
var secp256k1 = new elliptic_1.ec('secp256k1');
function computeSharedSecret(privateKey, publicKey) {

@@ -24,3 +22,8 @@ var ecdh = (0, crypto_1.createECDH)('secp256k1');

function ensureCompressed(publicKey) {
return secp256k1.keyFromPublic(ensureUncompressedPrefix(publicKey), 'hex').getPublic(true, 'hex');
// NOTE: elliptic is disabled elsewhere in this library to prevent
// accidental signing of truncated messages.
// tslint:disable-next-line:import-blacklist
var EC = require('elliptic').ec;
var ec = new EC('secp256k1');
return ec.keyFromPublic(ensureUncompressedPrefix(publicKey), 'hex').getPublic(true, 'hex');
}

@@ -30,3 +33,8 @@ exports.ensureCompressed = ensureCompressed;

var noLeading0x = (0, address_1.trimLeading0x)(publicKey);
var uncompressed = secp256k1
// NOTE: elliptic is disabled elsewhere in this library to prevent
// accidental signing of truncated messages.
// tslint:disable-next-line:import-blacklist
var EC = require('elliptic').ec;
var ec = new EC('secp256k1');
var uncompressed = ec
.keyFromPublic(ensureUncompressedPrefix(noLeading0x), 'hex')

@@ -33,0 +41,0 @@ .getPublic(false, 'hex');

@@ -11,4 +11,2 @@ /**

var crypto_1 = require("crypto");
var elliptic_1 = require("elliptic");
var ec = new elliptic_1.ec('secp256k1');
exports.IV_LENGTH = 16;

@@ -124,2 +122,7 @@ /**

function Encrypt(pubKeyTo, plaintext) {
// NOTE: elliptic is disabled elsewhere in this library to prevent
// accidental signing of truncated messages.
// tslint:disable-next-line:import-blacklist
var EC = require('elliptic').ec;
var ec = new EC('secp256k1');
var ephemPrivKey = ec.keyFromPrivate((0, crypto_1.randomBytes)(32));

@@ -150,2 +153,7 @@ var ephemPubKey = ephemPrivKey.getPublic(false, 'hex');

var symmetricEncrypted = encrypted.slice(65);
// NOTE: elliptic is disabled elsewhere in this library to prevent
// accidental signing of truncated messages.
// tslint:disable-next-line:import-blacklist
var EC = require('elliptic').ec;
var ec = new EC('secp256k1');
var ephemPubKey = ec.keyFromPublic(ephemPubKeyEncoded).getPublic();

@@ -152,0 +160,0 @@ var px = ec.keyFromPrivate(privKey).derive(ephemPubKey);

@@ -6,3 +6,2 @@ import * as AddressUtils from './address';

export * from './contacts';
export * from './countries';
export * from './currencies';

@@ -13,5 +12,4 @@ export * from './dappkit';

export { IstanbulUtils } from './istanbul';
export { PhoneNumberUtils } from './phoneNumbers';
export { SignatureUtils } from './signatureUtils';
export { StringUtils } from './string';
export { AddressUtils };

@@ -25,3 +25,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.AddressUtils = exports.StringUtils = exports.SignatureUtils = exports.PhoneNumberUtils = exports.IstanbulUtils = exports.ECIES = exports.DataEncryptionKeyUtils = exports.CommentEncryptionUtils = exports.AttestationUtils = exports.AccountUtils = void 0;
exports.AddressUtils = exports.StringUtils = exports.SignatureUtils = exports.IstanbulUtils = exports.ECIES = exports.DataEncryptionKeyUtils = exports.CommentEncryptionUtils = exports.AttestationUtils = exports.AccountUtils = void 0;
var AddressUtils = __importStar(require("./address"));

@@ -36,3 +36,2 @@ exports.AddressUtils = AddressUtils;

__exportStar(require("./contacts"), exports);
__exportStar(require("./countries"), exports);
__exportStar(require("./currencies"), exports);

@@ -46,4 +45,2 @@ __exportStar(require("./dappkit"), exports);

Object.defineProperty(exports, "IstanbulUtils", { enumerable: true, get: function () { return istanbul_1.IstanbulUtils; } });
var phoneNumbers_1 = require("./phoneNumbers");
Object.defineProperty(exports, "PhoneNumberUtils", { enumerable: true, get: function () { return phoneNumbers_1.PhoneNumberUtils; } });
var signatureUtils_1 = require("./signatureUtils");

@@ -50,0 +47,0 @@ Object.defineProperty(exports, "SignatureUtils", { enumerable: true, get: function () { return signatureUtils_1.SignatureUtils; } });

@@ -1,4 +0,1 @@

import { BaseProps } from '@celo/base/lib/inputValidation';
export { BaseProps, validateDecimal, validateInteger, ValidatorKind, } from '@celo/base/lib/inputValidation';
export declare function validatePhone(input: string, countryCallingCode?: string): string;
export declare function validateInput(input: string, props: BaseProps): string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateInput = exports.validatePhone = exports.ValidatorKind = exports.validateInteger = exports.validateDecimal = void 0;
var inputValidation_1 = require("@celo/base/lib/inputValidation");
var phoneNumbers_1 = require("./phoneNumbers");
exports.ValidatorKind = exports.validateInteger = exports.validateDecimal = void 0;
// Exports moved to @celo/base, forwarding them
// here for backwards compatibility
var inputValidation_2 = require("@celo/base/lib/inputValidation");
Object.defineProperty(exports, "validateDecimal", { enumerable: true, get: function () { return inputValidation_2.validateDecimal; } });
Object.defineProperty(exports, "validateInteger", { enumerable: true, get: function () { return inputValidation_2.validateInteger; } });
Object.defineProperty(exports, "ValidatorKind", { enumerable: true, get: function () { return inputValidation_2.ValidatorKind; } });
function validatePhone(input, countryCallingCode) {
input = input.replace(/[^0-9()\- ]/g, '');
if (!countryCallingCode) {
return input;
}
var displayNumber = (0, phoneNumbers_1.getDisplayPhoneNumber)(input, countryCallingCode);
if (!displayNumber) {
return input;
}
return displayNumber;
}
exports.validatePhone = validatePhone;
function validateInput(input, props) {
if (!props.validator && !props.customValidator) {
return input;
}
switch (props.validator) {
case 'decimal':
return (0, inputValidation_1.validateDecimal)(input, props.decimalSeparator);
case 'integer':
return (0, inputValidation_1.validateInteger)(input);
case 'phone':
return validatePhone(input, props.countryCallingCode);
case 'custom': {
if (props.customValidator) {
return props.customValidator(input);
}
}
}
throw new Error('Unhandled input validator');
}
exports.validateInput = validateInput;
var inputValidation_1 = require("@celo/base/lib/inputValidation");
Object.defineProperty(exports, "validateDecimal", { enumerable: true, get: function () { return inputValidation_1.validateDecimal; } });
Object.defineProperty(exports, "validateInteger", { enumerable: true, get: function () { return inputValidation_1.validateInteger; } });
Object.defineProperty(exports, "ValidatorKind", { enumerable: true, get: function () { return inputValidation_1.ValidatorKind; } });
//# sourceMappingURL=inputValidation.js.map

@@ -5,6 +5,2 @@ import * as t from 'io-ts';

export declare const JSONStringType: t.Type<string, string, unknown>;
/**
* @deprecated moved to @celo/phone-utils will be removed in next major version
*/
export declare const E164PhoneNumberType: t.Type<string, string, unknown>;
export declare const AddressType: t.Type<string, string, unknown>;

@@ -14,85 +10,3 @@ export declare const PublicKeyType: t.Type<string, string, unknown>;

export declare const SaltType: t.StringC;
/**
* @deprecated moved to @celo/phone-utils will be removed in next major version
*/
export declare const AttestationServiceStatusResponseType: t.TypeC<{
status: t.LiteralC<"ok">;
smsProviders: t.ArrayC<t.StringC>;
blacklistedRegionCodes: t.UnionC<[t.ArrayC<t.StringC>, t.UndefinedC]>;
accountAddress: t.Type<string, string, unknown>;
signature: t.UnionC<[t.StringC, t.UndefinedC]>;
version: t.StringC;
latestBlock: t.NumberC;
ageOfLatestBlock: t.NumberC;
isNodeSyncing: t.BooleanC;
appSignature: t.StringC;
smsProvidersRandomized: t.BooleanC;
maxDeliveryAttempts: t.NumberC;
maxRerequestMins: t.NumberC;
twilioVerifySidProvided: t.BooleanC;
}>;
/**
* @deprecated moved to @celo/phone-utils will be removed in next major version
*/
export declare const AttestationServiceTestRequestType: t.TypeC<{
phoneNumber: t.Type<string, string, unknown>;
message: t.StringC;
signature: t.StringC;
provider: t.UnionC<[t.StringC, t.UndefinedC]>;
}>;
/**
* @deprecated moved to @celo/phone-utils will be removed in next major version
*/
export declare type AttestationServiceTestRequest = t.TypeOf<typeof AttestationServiceTestRequestType>;
export declare type Signature = t.TypeOf<typeof SignatureType>;
export declare type Address = t.TypeOf<typeof AddressType>;
/**
* @deprecated moved to @celo/phone-utils will be removed in next major version
*/
export declare type E164Number = t.TypeOf<typeof E164PhoneNumberType>;
/**
* @deprecated moved to @celo/phone-utils will be removed in next major version
*/
export declare const AttestationRequestType: t.TypeC<{
phoneNumber: t.Type<string, string, unknown>;
account: t.Type<string, string, unknown>;
issuer: t.Type<string, string, unknown>;
salt: t.UnionC<[t.UndefinedC, t.StringC]>;
smsRetrieverAppSig: t.UnionC<[t.UndefinedC, t.StringC]>;
securityCodePrefix: t.UnionC<[t.UndefinedC, t.StringC]>;
language: t.UnionC<[t.UndefinedC, t.StringC]>;
}>;
/**
* @deprecated moved to @celo/phone-utils will be removed in next major version
*/
export declare type AttestationRequest = t.TypeOf<typeof AttestationRequestType>;
/**
* @deprecated moved to @celo/phone-utils will be removed in next major version
*/
export declare const GetAttestationRequestType: t.TypeC<{
phoneNumber: t.Type<string, string, unknown>;
account: t.Type<string, string, unknown>;
issuer: t.Type<string, string, unknown>;
salt: t.UnionC<[t.UndefinedC, t.StringC]>;
securityCode: t.UnionC<[t.UndefinedC, t.StringC]>;
}>;
/**
* @deprecated moved to @celo/phone-utils will be removed in next major version
*/
export declare type GetAttestationRequest = t.TypeOf<typeof GetAttestationRequestType>;
export declare const AttestationResponseType: t.TypeC<{
success: t.BooleanC;
error: t.UnionC<[t.UndefinedC, t.StringC]>;
errors: t.UnionC<[t.UndefinedC, t.StringC]>;
provider: t.UnionC<[t.UndefinedC, t.StringC]>;
identifier: t.UnionC<[t.UndefinedC, t.StringC]>;
account: t.UnionC<[t.UndefinedC, t.Type<string, string, unknown>]>;
issuer: t.UnionC<[t.UndefinedC, t.Type<string, string, unknown>]>;
status: t.UnionC<[t.UndefinedC, t.StringC]>;
attempt: t.UnionC<[t.UndefinedC, t.NumberC]>;
countryCode: t.UnionC<[t.UndefinedC, t.StringC]>;
duration: t.UnionC<[t.UndefinedC, t.NumberC]>;
salt: t.UnionC<[t.UndefinedC, t.StringC]>;
attestationCode: t.UnionC<[t.UndefinedC, t.StringC]>;
}>;
export declare type AttestationResponse = t.TypeOf<typeof AttestationResponseType>;

@@ -22,3 +22,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.AttestationResponseType = exports.GetAttestationRequestType = exports.AttestationRequestType = exports.AttestationServiceTestRequestType = exports.AttestationServiceStatusResponseType = exports.SaltType = exports.SignatureType = exports.PublicKeyType = exports.AddressType = exports.E164PhoneNumberType = exports.JSONStringType = exports.UrlType = exports.URL_REGEX = exports.isValidUrl = void 0;
exports.SaltType = exports.SignatureType = exports.PublicKeyType = exports.AddressType = exports.JSONStringType = exports.UrlType = exports.URL_REGEX = exports.isValidUrl = void 0;
var io_1 = require("@celo/base/lib/io");

@@ -29,3 +29,2 @@ var ethereumjs_util_1 = require("ethereumjs-util");

var address_1 = require("./address");
var phoneNumbers_1 = require("./phoneNumbers");
// Exports moved to @celo/base, forwarding them

@@ -54,12 +53,2 @@ // here for backwards compatibility

}, String);
/**
* @deprecated moved to @celo/phone-utils will be removed in next major version
*/
exports.E164PhoneNumberType = new t.Type('E164Number', t.string.is, function (input, context) {
return Either_1.either.chain(t.string.validate(input, context), function (stringValue) {
return (0, phoneNumbers_1.isE164NumberStrict)(stringValue)
? t.success(stringValue)
: t.failure(stringValue, context, 'is not a valid e164 number');
});
}, String);
exports.AddressType = new t.Type('Address', t.string.is, function (input, context) {

@@ -81,80 +70,2 @@ return Either_1.either.chain(t.string.validate(input, context), function (stringValue) {

exports.SaltType = t.string;
/**
* @deprecated moved to @celo/phone-utils will be removed in next major version
*/
exports.AttestationServiceStatusResponseType = t.type({
status: t.literal('ok'),
smsProviders: t.array(t.string),
blacklistedRegionCodes: t.union([t.array(t.string), t.undefined]),
accountAddress: exports.AddressType,
signature: t.union([exports.SignatureType, t.undefined]),
version: t.string,
latestBlock: t.number,
ageOfLatestBlock: t.number,
isNodeSyncing: t.boolean,
appSignature: t.string,
smsProvidersRandomized: t.boolean,
maxDeliveryAttempts: t.number,
maxRerequestMins: t.number,
twilioVerifySidProvided: t.boolean,
});
/**
* @deprecated moved to @celo/phone-utils will be removed in next major version
*/
exports.AttestationServiceTestRequestType = t.type({
phoneNumber: exports.E164PhoneNumberType,
message: t.string,
signature: exports.SignatureType,
provider: t.union([t.string, t.undefined]),
});
/**
* @deprecated moved to @celo/phone-utils will be removed in next major version
*/
exports.AttestationRequestType = t.type({
phoneNumber: exports.E164PhoneNumberType,
account: exports.AddressType,
issuer: exports.AddressType,
// io-ts way of defining optional key-value pair
salt: t.union([t.undefined, exports.SaltType]),
smsRetrieverAppSig: t.union([t.undefined, t.string]),
// if specified, the message sent will be short random number prefixed by this string
securityCodePrefix: t.union([t.undefined, t.string]),
language: t.union([t.undefined, t.string]),
});
/**
* @deprecated moved to @celo/phone-utils will be removed in next major version
*/
exports.GetAttestationRequestType = t.type({
phoneNumber: exports.E164PhoneNumberType,
account: exports.AddressType,
issuer: exports.AddressType,
// io-ts way of defining optional key-value pair
salt: t.union([t.undefined, exports.SaltType]),
// if the value supplied matches the stored security code, the response will include the complete message
securityCode: t.union([t.undefined, t.string]),
});
exports.AttestationResponseType = t.type({
// Always returned in 1.0.x
success: t.boolean,
// Returned for errors in 1.0.x
error: t.union([t.undefined, t.string]),
// Stringifyed JSON dict of dicts, mapping attempt to error info.
errors: t.union([t.undefined, t.string]),
// Returned for successful send in 1.0.x
provider: t.union([t.undefined, t.string]),
// New fields
identifier: t.union([t.undefined, t.string]),
account: t.union([t.undefined, exports.AddressType]),
issuer: t.union([t.undefined, exports.AddressType]),
status: t.union([t.undefined, t.string]),
attempt: t.union([t.undefined, t.number]),
countryCode: t.union([t.undefined, t.string]),
// Time to receive eventual delivery/failure (inc retries)
duration: t.union([t.undefined, t.number]),
// Only used by test endpoint to return randomly generated salt.
// Never return a user-supplied salt.
salt: t.union([t.undefined, t.string]),
// only returned if the request supplied the correct security code
attestationCode: t.union([t.undefined, t.string]),
});
//# sourceMappingURL=io.js.map
{
"name": "@celo/utils",
"version": "1.5.2",
"version": "2.0.0-alpha1",
"description": "Celo common utils",

@@ -22,8 +22,6 @@ "author": "Celo",

"dependencies": {
"@celo/base": "1.5.2",
"@celo/base": "2.0.0-alpha1",
"@types/country-data": "^0.0.0",
"@types/elliptic": "^6.4.9",
"@types/ethereumjs-util": "^5.2.0",
"@types/google-libphonenumber": "^7.4.17",
"@types/lodash": "^4.14.170",
"@types/node": "^10.12.18",

@@ -38,11 +36,7 @@ "@types/randombytes": "^2.0.0",

"buffer-reverse": "^1.0.1",
"country-data": "^0.0.31",
"crypto-js": "^3.1.9-1",
"elliptic": "^6.5.4",
"ethereumjs-util": "^5.2.0",
"fp-ts": "2.1.1",
"google-libphonenumber": "^3.2.15",
"io-ts": "2.0.1",
"keccak256": "^1.0.0",
"lodash": "^4.17.21",
"numeral": "^2.0.6",

@@ -49,0 +43,0 @@ "web3-eth-abi": "1.3.6",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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