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

@airgap/beacon-utils

Package Overview
Dependencies
Maintainers
1
Versions
117
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@airgap/beacon-utils - npm Package Compare versions

Comparing version 0.0.1-beta.9 to 0.0.1-beta.10

1

dist/cjs/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.recipientString = exports.openCryptobox = exports.sealCryptobox = exports.getHexHash = exports.encryptCryptoboxPayload = exports.decryptCryptoboxPayload = exports.getAddressFromPublicKey = exports.toHex = exports.getKeypairFromSeed = exports.ExposedPromiseStatus = exports.ExposedPromise = exports.keys = void 0;
var keys_1 = require("./utils/keys");

@@ -4,0 +5,0 @@ Object.defineProperty(exports, "keys", { enumerable: true, get: function () { return keys_1.keys; } });

43

dist/cjs/utils/crypto.js
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -59,3 +40,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

exports.recipientString = exports.getAddressFromPublicKey = exports.openCryptobox = exports.sealCryptobox = exports.decryptCryptoboxPayload = exports.encryptCryptoboxPayload = exports.getKeypairFromSeed = exports.getHexHash = exports.toHex = void 0;
var bs58check = __importStar(require("bs58check"));
var bs58check = require("bs58check");
var libsodium_wrappers_1 = require("libsodium-wrappers");

@@ -85,3 +66,3 @@ /* eslint-disable prefer-arrow/prefer-arrow-functions */

_a.sent();
return [2 /*return*/, toHex(libsodium_wrappers_1.crypto_generichash(32, key))];
return [2 /*return*/, toHex((0, libsodium_wrappers_1.crypto_generichash)(32, key))];
}

@@ -104,3 +85,3 @@ });

_a.sent();
return [2 /*return*/, libsodium_wrappers_1.crypto_sign_seed_keypair(libsodium_wrappers_1.crypto_generichash(32, libsodium_wrappers_1.from_string(seed)))];
return [2 /*return*/, (0, libsodium_wrappers_1.crypto_sign_seed_keypair)((0, libsodium_wrappers_1.crypto_generichash)(32, (0, libsodium_wrappers_1.from_string)(seed)))];
}

@@ -125,6 +106,6 @@ });

_a.sent();
nonce = Buffer.from(libsodium_wrappers_1.randombytes_buf(libsodium_wrappers_1.crypto_secretbox_NONCEBYTES));
nonce = Buffer.from((0, libsodium_wrappers_1.randombytes_buf)(libsodium_wrappers_1.crypto_secretbox_NONCEBYTES));
combinedPayload = Buffer.concat([
nonce,
Buffer.from(libsodium_wrappers_1.crypto_secretbox_easy(Buffer.from(message, 'utf8'), nonce, sharedKey))
Buffer.from((0, libsodium_wrappers_1.crypto_secretbox_easy)(Buffer.from(message, 'utf8'), nonce, sharedKey))
]);

@@ -153,3 +134,3 @@ return [2 /*return*/, toHex(combinedPayload)];

ciphertext = payload.slice(libsodium_wrappers_1.crypto_secretbox_NONCEBYTES);
return [2 /*return*/, Buffer.from(libsodium_wrappers_1.crypto_secretbox_open_easy(ciphertext, nonce, sharedKey)).toString('utf8')];
return [2 /*return*/, Buffer.from((0, libsodium_wrappers_1.crypto_secretbox_open_easy)(ciphertext, nonce, sharedKey)).toString('utf8')];
}

@@ -174,5 +155,5 @@ });

_a.sent();
kxSelfPublicKey = libsodium_wrappers_1.crypto_sign_ed25519_pk_to_curve25519(Buffer.from(publicKey)) // Secret bytes to scalar bytes
kxSelfPublicKey = (0, libsodium_wrappers_1.crypto_sign_ed25519_pk_to_curve25519)(Buffer.from(publicKey)) // Secret bytes to scalar bytes
;
encryptedMessage = libsodium_wrappers_1.crypto_box_seal(payload, kxSelfPublicKey);
encryptedMessage = (0, libsodium_wrappers_1.crypto_box_seal)(payload, kxSelfPublicKey);
return [2 /*return*/, toHex(encryptedMessage)];

@@ -199,7 +180,7 @@ }

_a.sent();
kxSelfPrivateKey = libsodium_wrappers_1.crypto_sign_ed25519_sk_to_curve25519(Buffer.from(privateKey)) // Secret bytes to scalar bytes
kxSelfPrivateKey = (0, libsodium_wrappers_1.crypto_sign_ed25519_sk_to_curve25519)(Buffer.from(privateKey)) // Secret bytes to scalar bytes
;
kxSelfPublicKey = libsodium_wrappers_1.crypto_sign_ed25519_pk_to_curve25519(Buffer.from(publicKey)) // Secret bytes to scalar bytes
kxSelfPublicKey = (0, libsodium_wrappers_1.crypto_sign_ed25519_pk_to_curve25519)(Buffer.from(publicKey)) // Secret bytes to scalar bytes
;
decryptedMessage = libsodium_wrappers_1.crypto_box_seal_open(encryptedPayload, kxSelfPublicKey, kxSelfPrivateKey);
decryptedMessage = (0, libsodium_wrappers_1.crypto_box_seal_open)(encryptedPayload, kxSelfPublicKey, kxSelfPrivateKey);
return [2 /*return*/, Buffer.from(decryptedMessage).toString()];

@@ -260,3 +241,3 @@ }

}
payload = libsodium_wrappers_1.crypto_generichash(20, Buffer.from(plainPublicKey, 'hex'));
payload = (0, libsodium_wrappers_1.crypto_generichash)(20, Buffer.from(plainPublicKey, 'hex'));
return [2 /*return*/, bs58check.encode(Buffer.concat([prefix, Buffer.from(payload)]))];

@@ -263,0 +244,0 @@ }

@@ -6,3 +6,3 @@ export declare enum ExposedPromiseStatus {

}
declare type Resolve<T> = (value?: T) => void;
declare type Resolve<T> = (value: T) => void;
declare type Reject<U> = (reason?: U) => void;

@@ -26,3 +26,3 @@ /**

constructor();
static resolve<T>(value?: T): ExposedPromise<T>;
static resolve<T>(value: T): ExposedPromise<T>;
static reject<T = never, U = unknown>(reason?: U): ExposedPromise<T, U>;

@@ -29,0 +29,0 @@ isPending(): boolean;

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

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import * as bs58check from 'bs58check';

@@ -27,7 +18,5 @@ import { ready, crypto_generichash, crypto_sign_seed_keypair, from_string, randombytes_buf, crypto_secretbox_NONCEBYTES, crypto_secretbox_easy, crypto_secretbox_open_easy, crypto_sign_ed25519_pk_to_curve25519, crypto_sign_ed25519_sk_to_curve25519, crypto_box_seal, crypto_box_seal_open } from 'libsodium-wrappers';

*/
export function getHexHash(key) {
return __awaiter(this, void 0, void 0, function* () {
yield ready;
return toHex(crypto_generichash(32, key));
});
export async function getHexHash(key) {
await ready;
return toHex(crypto_generichash(32, key));
}

@@ -39,7 +28,5 @@ /**

*/
export function getKeypairFromSeed(seed) {
return __awaiter(this, void 0, void 0, function* () {
yield ready;
return crypto_sign_seed_keypair(crypto_generichash(32, from_string(seed)));
});
export async function getKeypairFromSeed(seed) {
await ready;
return crypto_sign_seed_keypair(crypto_generichash(32, from_string(seed)));
}

@@ -52,12 +39,10 @@ /**

*/
export function encryptCryptoboxPayload(message, sharedKey) {
return __awaiter(this, void 0, void 0, function* () {
yield ready;
const nonce = Buffer.from(randombytes_buf(crypto_secretbox_NONCEBYTES));
const combinedPayload = Buffer.concat([
nonce,
Buffer.from(crypto_secretbox_easy(Buffer.from(message, 'utf8'), nonce, sharedKey))
]);
return toHex(combinedPayload);
});
export async function encryptCryptoboxPayload(message, sharedKey) {
await ready;
const nonce = Buffer.from(randombytes_buf(crypto_secretbox_NONCEBYTES));
const combinedPayload = Buffer.concat([
nonce,
Buffer.from(crypto_secretbox_easy(Buffer.from(message, 'utf8'), nonce, sharedKey))
]);
return toHex(combinedPayload);
}

@@ -70,9 +55,7 @@ /**

*/
export function decryptCryptoboxPayload(payload, sharedKey) {
return __awaiter(this, void 0, void 0, function* () {
yield ready;
const nonce = payload.slice(0, crypto_secretbox_NONCEBYTES);
const ciphertext = payload.slice(crypto_secretbox_NONCEBYTES);
return Buffer.from(crypto_secretbox_open_easy(ciphertext, nonce, sharedKey)).toString('utf8');
});
export async function decryptCryptoboxPayload(payload, sharedKey) {
await ready;
const nonce = payload.slice(0, crypto_secretbox_NONCEBYTES);
const ciphertext = payload.slice(crypto_secretbox_NONCEBYTES);
return Buffer.from(crypto_secretbox_open_easy(ciphertext, nonce, sharedKey)).toString('utf8');
}

@@ -85,9 +68,7 @@ /**

*/
export function sealCryptobox(payload, publicKey) {
return __awaiter(this, void 0, void 0, function* () {
yield ready;
const kxSelfPublicKey = crypto_sign_ed25519_pk_to_curve25519(Buffer.from(publicKey)); // Secret bytes to scalar bytes
const encryptedMessage = crypto_box_seal(payload, kxSelfPublicKey);
return toHex(encryptedMessage);
});
export async function sealCryptobox(payload, publicKey) {
await ready;
const kxSelfPublicKey = crypto_sign_ed25519_pk_to_curve25519(Buffer.from(publicKey)); // Secret bytes to scalar bytes
const encryptedMessage = crypto_box_seal(payload, kxSelfPublicKey);
return toHex(encryptedMessage);
}

@@ -101,10 +82,8 @@ /**

*/
export function openCryptobox(encryptedPayload, publicKey, privateKey) {
return __awaiter(this, void 0, void 0, function* () {
yield ready;
const kxSelfPrivateKey = crypto_sign_ed25519_sk_to_curve25519(Buffer.from(privateKey)); // Secret bytes to scalar bytes
const kxSelfPublicKey = crypto_sign_ed25519_pk_to_curve25519(Buffer.from(publicKey)); // Secret bytes to scalar bytes
const decryptedMessage = crypto_box_seal_open(encryptedPayload, kxSelfPublicKey, kxSelfPrivateKey);
return Buffer.from(decryptedMessage).toString();
});
export async function openCryptobox(encryptedPayload, publicKey, privateKey) {
await ready;
const kxSelfPrivateKey = crypto_sign_ed25519_sk_to_curve25519(Buffer.from(privateKey)); // Secret bytes to scalar bytes
const kxSelfPublicKey = crypto_sign_ed25519_pk_to_curve25519(Buffer.from(publicKey)); // Secret bytes to scalar bytes
const decryptedMessage = crypto_box_seal_open(encryptedPayload, kxSelfPublicKey, kxSelfPrivateKey);
return Buffer.from(decryptedMessage).toString();
}

@@ -116,46 +95,44 @@ /**

*/
export function getAddressFromPublicKey(publicKey) {
return __awaiter(this, void 0, void 0, function* () {
yield ready;
const prefixes = {
// tz1...
edpk: {
length: 54,
prefix: Buffer.from(new Uint8Array([6, 161, 159]))
},
// tz2...
sppk: {
length: 55,
prefix: Buffer.from(new Uint8Array([6, 161, 161]))
},
// tz3...
p2pk: {
length: 55,
prefix: Buffer.from(new Uint8Array([6, 161, 164]))
}
};
let prefix;
let plainPublicKey;
if (publicKey.length === 64) {
prefix = prefixes.edpk.prefix;
plainPublicKey = publicKey;
export async function getAddressFromPublicKey(publicKey) {
await ready;
const prefixes = {
// tz1...
edpk: {
length: 54,
prefix: Buffer.from(new Uint8Array([6, 161, 159]))
},
// tz2...
sppk: {
length: 55,
prefix: Buffer.from(new Uint8Array([6, 161, 161]))
},
// tz3...
p2pk: {
length: 55,
prefix: Buffer.from(new Uint8Array([6, 161, 164]))
}
else {
const entries = Object.entries(prefixes);
for (let index = 0; index < entries.length; index++) {
const [key, value] = entries[index];
if (publicKey.startsWith(key) && publicKey.length === value.length) {
prefix = value.prefix;
const decoded = bs58check.decode(publicKey);
plainPublicKey = decoded.slice(key.length, decoded.length).toString('hex');
break;
}
};
let prefix;
let plainPublicKey;
if (publicKey.length === 64) {
prefix = prefixes.edpk.prefix;
plainPublicKey = publicKey;
}
else {
const entries = Object.entries(prefixes);
for (let index = 0; index < entries.length; index++) {
const [key, value] = entries[index];
if (publicKey.startsWith(key) && publicKey.length === value.length) {
prefix = value.prefix;
const decoded = bs58check.decode(publicKey);
plainPublicKey = decoded.slice(key.length, decoded.length).toString('hex');
break;
}
}
if (!prefix || !plainPublicKey) {
throw new Error(`invalid publicKey: ${publicKey}`);
}
const payload = crypto_generichash(20, Buffer.from(plainPublicKey, 'hex'));
return bs58check.encode(Buffer.concat([prefix, Buffer.from(payload)]));
});
}
if (!prefix || !plainPublicKey) {
throw new Error(`invalid publicKey: ${publicKey}`);
}
const payload = crypto_generichash(20, Buffer.from(plainPublicKey, 'hex'));
return bs58check.encode(Buffer.concat([prefix, Buffer.from(payload)]));
}

@@ -162,0 +139,0 @@ /**

@@ -6,3 +6,3 @@ export declare enum ExposedPromiseStatus {

}
declare type Resolve<T> = (value?: T) => void;
declare type Resolve<T> = (value: T) => void;
declare type Reject<U> = (reason?: U) => void;

@@ -26,3 +26,3 @@ /**

constructor();
static resolve<T>(value?: T): ExposedPromise<T>;
static resolve<T>(value: T): ExposedPromise<T>;
static reject<T = never, U = unknown>(reason?: U): ExposedPromise<T, U>;

@@ -29,0 +29,0 @@ isPending(): boolean;

@@ -14,6 +14,27 @@ export var ExposedPromiseStatus;

export class ExposedPromise {
_promise;
_resolve = notInitialized;
_reject = notInitialized;
_status = ExposedPromiseStatus.PENDING;
_promiseResult;
_promiseError;
get promise() {
return this._promise;
}
get resolve() {
return this._resolve;
}
get reject() {
return this._reject;
}
get status() {
return this._status;
}
get promiseResult() {
return this._promiseResult;
}
get promiseError() {
return this._promiseError;
}
constructor() {
this._resolve = notInitialized;
this._reject = notInitialized;
this._status = ExposedPromiseStatus.PENDING;
this._promise = new Promise((innerResolve, innerReject) => {

@@ -40,20 +61,2 @@ this._resolve = (value) => {

}
get promise() {
return this._promise;
}
get resolve() {
return this._resolve;
}
get reject() {
return this._reject;
}
get status() {
return this._status;
}
get promiseResult() {
return this._promiseResult;
}
get promiseError() {
return this._promiseError;
}
static resolve(value) {

@@ -60,0 +63,0 @@ const promise = new ExposedPromise();

{
"name": "@airgap/beacon-utils",
"version": "0.0.1-beta.9",
"version": "0.0.1-beta.10",
"description": "> TODO: description",

@@ -44,3 +44,3 @@ "author": "Andreas Gassmann <andreas@andreasgassmann.ch>",

},
"gitHead": "d23e9fb9724b5cbc82b18a2cd29fe1dd15403ac4"
"gitHead": "dee593d5e9773cfeb53397c1f5824afca2f5d5a4"
}

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