@airgap/beacon-utils
Advanced tools
Comparing version 4.0.12 to 4.0.13-beta.0
export { keys } from './utils/keys'; | ||
export { ExposedPromise, ExposedPromiseStatus } from './utils/exposed-promise'; | ||
export { getKeypairFromSeed, toHex, getAddressFromPublicKey, decryptCryptoboxPayload, encryptCryptoboxPayload, getHexHash, sealCryptobox, openCryptobox, recipientString, signMessage, prefixPublicKey } from './utils/crypto'; | ||
export { getKeypairFromSeed, toHex, getAddressFromPublicKey, decryptCryptoboxPayload, encryptCryptoboxPayload, getHexHash, sealCryptobox, openCryptobox, recipientString, signMessage, isValidAddress, prefixPublicKey } from './utils/crypto'; | ||
export { generateGUID } from './utils/generate-uuid'; | ||
export declare const CONTRACT_PREFIX = "KT1"; | ||
export declare const secretbox_NONCEBYTES = 24; | ||
export declare const secretbox_MACBYTES = 16; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.secretbox_MACBYTES = exports.secretbox_NONCEBYTES = exports.generateGUID = exports.prefixPublicKey = exports.signMessage = 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; | ||
exports.secretbox_MACBYTES = exports.secretbox_NONCEBYTES = exports.CONTRACT_PREFIX = exports.generateGUID = exports.prefixPublicKey = exports.isValidAddress = exports.signMessage = 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"); | ||
@@ -20,7 +20,9 @@ Object.defineProperty(exports, "keys", { enumerable: true, get: function () { return keys_1.keys; } }); | ||
Object.defineProperty(exports, "signMessage", { enumerable: true, get: function () { return crypto_1.signMessage; } }); | ||
Object.defineProperty(exports, "isValidAddress", { enumerable: true, get: function () { return crypto_1.isValidAddress; } }); | ||
Object.defineProperty(exports, "prefixPublicKey", { enumerable: true, get: function () { return crypto_1.prefixPublicKey; } }); | ||
var generate_uuid_1 = require("./utils/generate-uuid"); | ||
Object.defineProperty(exports, "generateGUID", { enumerable: true, get: function () { return generate_uuid_1.generateGUID; } }); | ||
exports.CONTRACT_PREFIX = 'KT1'; | ||
exports.secretbox_NONCEBYTES = 24; // crypto_secretbox_NONCEBYTES | ||
exports.secretbox_MACBYTES = 16; // crypto_secretbox_MACBYTES | ||
//# sourceMappingURL=index.js.map |
@@ -74,1 +74,2 @@ /// <reference types="node" /> | ||
}) => Promise<string>; | ||
export declare const isValidAddress: (address: string) => boolean; |
@@ -11,41 +11,14 @@ "use strict"; | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.signMessage = exports.recipientString = exports.prefixPublicKey = exports.getAddressFromPublicKey = exports.openCryptobox = exports.sealCryptobox = exports.decryptCryptoboxPayload = exports.encryptCryptoboxPayload = exports.getKeypairFromSeed = exports.getHexHash = exports.toHex = exports.secretbox_MACBYTES = exports.secretbox_NONCEBYTES = void 0; | ||
var bs58check = require("bs58check"); | ||
var nacl_1 = require("@stablelib/nacl"); | ||
var random_1 = require("@stablelib/random"); | ||
var utf8_1 = require("@stablelib/utf8"); | ||
var blake2b_1 = require("@stablelib/blake2b"); | ||
var ed25519_1 = require("@stablelib/ed25519"); | ||
var ed25519_2 = require("@stablelib/ed25519"); | ||
var blake2b_2 = require("@stablelib/blake2b"); | ||
var bytes_1 = require("@stablelib/bytes"); | ||
var ed25519_3 = require("@stablelib/ed25519"); | ||
exports.isValidAddress = exports.signMessage = exports.recipientString = exports.prefixPublicKey = exports.getAddressFromPublicKey = exports.openCryptobox = exports.sealCryptobox = exports.decryptCryptoboxPayload = exports.encryptCryptoboxPayload = exports.getKeypairFromSeed = exports.getHexHash = exports.toHex = exports.secretbox_MACBYTES = exports.secretbox_NONCEBYTES = void 0; | ||
const bs58check = require("bs58check"); | ||
const nacl_1 = require("@stablelib/nacl"); | ||
const random_1 = require("@stablelib/random"); | ||
const utf8_1 = require("@stablelib/utf8"); | ||
const blake2b_1 = require("@stablelib/blake2b"); | ||
const ed25519_1 = require("@stablelib/ed25519"); | ||
const ed25519_2 = require("@stablelib/ed25519"); | ||
const blake2b_2 = require("@stablelib/blake2b"); | ||
const bytes_1 = require("@stablelib/bytes"); | ||
const ed25519_3 = require("@stablelib/ed25519"); | ||
exports.secretbox_NONCEBYTES = 24; // crypto_secretbox_NONCEBYTES | ||
@@ -70,9 +43,7 @@ exports.secretbox_MACBYTES = 16; // crypto_secretbox_MACBYTES | ||
function getHexHash(key) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
if (typeof key === 'string') { | ||
return [2 /*return*/, toHex((0, blake2b_1.hash)((0, utf8_1.encode)(key), 32))]; | ||
} | ||
return [2 /*return*/, toHex((0, blake2b_1.hash)(key, 32))]; | ||
}); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (typeof key === 'string') { | ||
return toHex((0, blake2b_1.hash)((0, utf8_1.encode)(key), 32)); | ||
} | ||
return toHex((0, blake2b_1.hash)(key, 32)); | ||
}); | ||
@@ -87,6 +58,4 @@ } | ||
function getKeypairFromSeed(seed) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, (0, ed25519_1.generateKeyPairFromSeed)((0, blake2b_1.hash)((0, utf8_1.encode)(seed), 32))]; | ||
}); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return (0, ed25519_1.generateKeyPairFromSeed)((0, blake2b_1.hash)((0, utf8_1.encode)(seed), 32)); | ||
}); | ||
@@ -102,12 +71,9 @@ } | ||
function encryptCryptoboxPayload(message, sharedKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var nonce, combinedPayload; | ||
return __generator(this, function (_a) { | ||
nonce = Buffer.from((0, random_1.randomBytes)(exports.secretbox_NONCEBYTES)); | ||
combinedPayload = Buffer.concat([ | ||
nonce, | ||
Buffer.from((0, nacl_1.secretBox)(sharedKey, nonce, Buffer.from(message, 'utf8'))) | ||
]); | ||
return [2 /*return*/, toHex(combinedPayload)]; | ||
}); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const nonce = Buffer.from((0, random_1.randomBytes)(exports.secretbox_NONCEBYTES)); | ||
const combinedPayload = Buffer.concat([ | ||
nonce, | ||
Buffer.from((0, nacl_1.secretBox)(sharedKey, nonce, Buffer.from(message, 'utf8'))) | ||
]); | ||
return toHex(combinedPayload); | ||
}); | ||
@@ -123,13 +89,10 @@ } | ||
function decryptCryptoboxPayload(payload, sharedKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var nonce, ciphertext, openBox; | ||
return __generator(this, function (_a) { | ||
nonce = payload.slice(0, exports.secretbox_NONCEBYTES); | ||
ciphertext = payload.slice(exports.secretbox_NONCEBYTES); | ||
openBox = (0, nacl_1.openSecretBox)(sharedKey, nonce, ciphertext); | ||
if (!openBox) { | ||
throw new Error('Decryption failed'); | ||
} | ||
return [2 /*return*/, Buffer.from(openBox).toString('utf8')]; | ||
}); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const nonce = payload.slice(0, exports.secretbox_NONCEBYTES); | ||
const ciphertext = payload.slice(exports.secretbox_NONCEBYTES); | ||
const openBox = (0, nacl_1.openSecretBox)(sharedKey, nonce, ciphertext); | ||
if (!openBox) { | ||
throw new Error('Decryption failed'); | ||
} | ||
return Buffer.from(openBox).toString('utf8'); | ||
}); | ||
@@ -145,14 +108,10 @@ } | ||
function sealCryptobox(payload, otherPublicKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var kxOtherPublicKey, keypair, state, nonce, bytesPayload, encryptedMessage; | ||
return __generator(this, function (_a) { | ||
kxOtherPublicKey = (0, ed25519_2.convertPublicKeyToX25519)(Buffer.from(otherPublicKey)) // Secret bytes to scalar bytes | ||
; | ||
keypair = (0, nacl_1.generateKeyPair)(); | ||
state = new blake2b_2.BLAKE2b(24); | ||
nonce = state.update(keypair.publicKey, 32).update(kxOtherPublicKey, 32).digest(); | ||
bytesPayload = typeof payload === 'string' ? (0, utf8_1.encode)(payload) : payload; | ||
encryptedMessage = (0, nacl_1.box)(kxOtherPublicKey, keypair.secretKey, nonce, bytesPayload); | ||
return [2 /*return*/, toHex((0, bytes_1.concat)(keypair.publicKey, encryptedMessage))]; | ||
}); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const kxOtherPublicKey = (0, ed25519_2.convertPublicKeyToX25519)(Buffer.from(otherPublicKey)); // Secret bytes to scalar bytes | ||
const keypair = (0, nacl_1.generateKeyPair)(); | ||
const state = new blake2b_2.BLAKE2b(24); | ||
const nonce = state.update(keypair.publicKey, 32).update(kxOtherPublicKey, 32).digest(); | ||
const bytesPayload = typeof payload === 'string' ? (0, utf8_1.encode)(payload) : payload; | ||
const encryptedMessage = (0, nacl_1.box)(kxOtherPublicKey, keypair.secretKey, nonce, bytesPayload); | ||
return toHex((0, bytes_1.concat)(keypair.publicKey, encryptedMessage)); | ||
}); | ||
@@ -169,20 +128,15 @@ } | ||
function openCryptobox(encryptedPayload, publicKey, privateKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var kxSelfPrivateKey, kxSelfPublicKey, bytesPayload, epk, ciphertext, state, nonce, decryptedMessage2; | ||
return __generator(this, function (_a) { | ||
kxSelfPrivateKey = (0, ed25519_2.convertSecretKeyToX25519)(Buffer.from(privateKey)) // Secret bytes to scalar bytes | ||
; | ||
kxSelfPublicKey = (0, ed25519_2.convertPublicKeyToX25519)(Buffer.from(publicKey)) // Secret bytes to scalar bytes | ||
; | ||
bytesPayload = typeof encryptedPayload === 'string' ? (0, utf8_1.encode)(encryptedPayload) : encryptedPayload; | ||
epk = bytesPayload.slice(0, 32); | ||
ciphertext = bytesPayload.slice(32); | ||
state = new blake2b_2.BLAKE2b(24); | ||
nonce = state.update(epk, 32).update(kxSelfPublicKey, 32).digest(); | ||
decryptedMessage2 = (0, nacl_1.openBox)(epk, kxSelfPrivateKey, nonce, ciphertext); | ||
if (!decryptedMessage2) { | ||
throw new Error('Decryption failed'); | ||
} | ||
return [2 /*return*/, Buffer.from(decryptedMessage2).toString()]; | ||
}); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const kxSelfPrivateKey = (0, ed25519_2.convertSecretKeyToX25519)(Buffer.from(privateKey)); // Secret bytes to scalar bytes | ||
const kxSelfPublicKey = (0, ed25519_2.convertPublicKeyToX25519)(Buffer.from(publicKey)); // Secret bytes to scalar bytes | ||
const bytesPayload = typeof encryptedPayload === 'string' ? (0, utf8_1.encode)(encryptedPayload) : encryptedPayload; | ||
const epk = bytesPayload.slice(0, 32); | ||
const ciphertext = bytesPayload.slice(32); | ||
const state = new blake2b_2.BLAKE2b(24); | ||
const nonce = state.update(epk, 32).update(kxSelfPublicKey, 32).digest(); | ||
const decryptedMessage2 = (0, nacl_1.openBox)(epk, kxSelfPrivateKey, nonce, ciphertext); | ||
if (!decryptedMessage2) { | ||
throw new Error('Decryption failed'); | ||
} | ||
return Buffer.from(decryptedMessage2).toString(); | ||
}); | ||
@@ -197,44 +151,43 @@ } | ||
function getAddressFromPublicKey(publicKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var prefixes, prefix, plainPublicKey, entries, index, _a, key, value, decoded, payload; | ||
return __generator(this, function (_b) { | ||
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])) | ||
} | ||
}; | ||
if (publicKey.length === 64) { | ||
prefix = prefixes.edpk.prefix; | ||
plainPublicKey = publicKey; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
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 { | ||
entries = Object.entries(prefixes); | ||
for (index = 0; index < entries.length; index++) { | ||
_a = entries[index], key = _a[0], value = _a[1]; | ||
if (publicKey.startsWith(key) && publicKey.length === value.length) { | ||
prefix = value.prefix; | ||
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: ".concat(publicKey)); | ||
} | ||
payload = (0, blake2b_1.hash)(Buffer.from(plainPublicKey, 'hex'), 20); | ||
return [2 /*return*/, bs58check.encode(Buffer.concat([prefix, Buffer.from(payload)]))]; | ||
}); | ||
} | ||
if (!prefix || !plainPublicKey) { | ||
throw new Error(`invalid publicKey: ${publicKey}`); | ||
} | ||
const payload = (0, blake2b_1.hash)(Buffer.from(plainPublicKey, 'hex'), 20); | ||
return bs58check.encode(Buffer.concat([prefix, Buffer.from(payload)])); | ||
}); | ||
@@ -249,11 +202,8 @@ } | ||
function prefixPublicKey(publicKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var payload; | ||
return __generator(this, function (_a) { | ||
if (publicKey.length !== 64) { | ||
return [2 /*return*/, publicKey]; | ||
} | ||
payload = Buffer.from(publicKey, 'hex'); | ||
return [2 /*return*/, bs58check.encode(Buffer.concat([new Uint8Array([13, 15, 37, 217]), Buffer.from(payload)]))]; | ||
}); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (publicKey.length !== 64) { | ||
return publicKey; | ||
} | ||
const payload = Buffer.from(publicKey, 'hex'); | ||
return bs58check.encode(Buffer.concat([new Uint8Array([13, 15, 37, 217]), Buffer.from(payload)])); | ||
}); | ||
@@ -269,49 +219,46 @@ } | ||
function recipientString(recipientHash, relayServer) { | ||
return "@".concat(recipientHash, ":").concat(relayServer); | ||
return `@${recipientHash}:${relayServer}`; | ||
} | ||
exports.recipientString = recipientString; | ||
var toBuffer = function (message) { return __awaiter(void 0, void 0, void 0, function () { | ||
var adjustedMessage, buffer; | ||
return __generator(this, function (_a) { | ||
if (message.length % 2 !== 0) { | ||
return [2 /*return*/, (0, utf8_1.encode)(message)]; | ||
} | ||
adjustedMessage = message; | ||
if (message.startsWith('0x')) { | ||
adjustedMessage = message.slice(2); | ||
} | ||
buffer = Buffer.from(adjustedMessage, 'hex'); | ||
if (buffer.length === adjustedMessage.length / 2) { | ||
return [2 /*return*/, buffer]; | ||
} | ||
return [2 /*return*/, (0, utf8_1.encode)(message)]; | ||
}); | ||
}); }; | ||
var coinlibhash = function (message, size) { | ||
if (size === void 0) { size = 32; } | ||
return __awaiter(void 0, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, (0, blake2b_1.hash)(message, size)]; | ||
}); | ||
}); | ||
const toBuffer = (message) => __awaiter(void 0, void 0, void 0, function* () { | ||
if (message.length % 2 !== 0) { | ||
return (0, utf8_1.encode)(message); | ||
} | ||
let adjustedMessage = message; | ||
if (message.startsWith('0x')) { | ||
adjustedMessage = message.slice(2); | ||
} | ||
const buffer = Buffer.from(adjustedMessage, 'hex'); | ||
if (buffer.length === adjustedMessage.length / 2) { | ||
return buffer; | ||
} | ||
return (0, utf8_1.encode)(message); | ||
}); | ||
const coinlibhash = (message, size = 32) => __awaiter(void 0, void 0, void 0, function* () { | ||
return (0, blake2b_1.hash)(message, size); | ||
}); | ||
const signMessage = (message, keypair) => __awaiter(void 0, void 0, void 0, function* () { | ||
const bufferMessage = yield toBuffer(message); | ||
const edsigPrefix = new Uint8Array([9, 245, 205, 134, 18]); | ||
const hash = yield coinlibhash(bufferMessage); | ||
const rawSignature = (0, ed25519_3.sign)(keypair.secretKey, hash); | ||
const signature = bs58check.encode(Buffer.concat([Buffer.from(edsigPrefix), Buffer.from(rawSignature)])); | ||
return signature; | ||
}); | ||
exports.signMessage = signMessage; | ||
const isValidAddress = (address) => { | ||
const prefixes = ['tz1', 'tz2', 'tz3', 'tz4', 'KT1', 'txr1', 'sr1']; | ||
if (!prefixes.some((p) => address.toLowerCase().startsWith(p.toLowerCase()))) { | ||
return false; | ||
} | ||
try { | ||
bs58check.decode(address); | ||
} | ||
catch (error) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
var signMessage = function (message, keypair) { return __awaiter(void 0, void 0, void 0, function () { | ||
var bufferMessage, edsigPrefix, hash, rawSignature, signature; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, toBuffer(message)]; | ||
case 1: | ||
bufferMessage = _a.sent(); | ||
edsigPrefix = new Uint8Array([9, 245, 205, 134, 18]); | ||
return [4 /*yield*/, coinlibhash(bufferMessage)]; | ||
case 2: | ||
hash = _a.sent(); | ||
rawSignature = (0, ed25519_3.sign)(keypair.secretKey, hash); | ||
signature = bs58check.encode(Buffer.concat([Buffer.from(edsigPrefix), Buffer.from(rawSignature)])); | ||
return [2 /*return*/, signature]; | ||
} | ||
}); | ||
}); }; | ||
exports.signMessage = signMessage; | ||
exports.isValidAddress = isValidAddress; | ||
/* eslint-enable prefer-arrow/prefer-arrow-functions */ | ||
//# sourceMappingURL=crypto.js.map |
@@ -6,4 +6,4 @@ export declare enum ExposedPromiseStatus { | ||
} | ||
declare type Resolve<T> = (value: T) => void; | ||
declare type Reject<U> = (reason?: U) => void; | ||
type Resolve<T> = (value: T) => void; | ||
type Reject<U> = (reason?: U) => void; | ||
/** | ||
@@ -10,0 +10,0 @@ * Exposed promise allow you to create a promise and then resolve it later, from the outside |
@@ -9,4 +9,4 @@ "use strict"; | ||
ExposedPromiseStatus["REJECTED"] = "rejected"; | ||
})(ExposedPromiseStatus = exports.ExposedPromiseStatus || (exports.ExposedPromiseStatus = {})); | ||
var notInitialized = function () { | ||
})(ExposedPromiseStatus || (exports.ExposedPromiseStatus = ExposedPromiseStatus = {})); | ||
const notInitialized = () => { | ||
throw new Error('ExposedPromise not initialized yet.'); | ||
@@ -17,25 +17,42 @@ }; | ||
*/ | ||
var ExposedPromise = /** @class */ (function () { | ||
function ExposedPromise() { | ||
var _this = this; | ||
class ExposedPromise { | ||
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(function (innerResolve, innerReject) { | ||
_this._resolve = function (value) { | ||
if (_this.isSettled()) { | ||
this._promise = new Promise((innerResolve, innerReject) => { | ||
this._resolve = (value) => { | ||
if (this.isSettled()) { | ||
return; | ||
} | ||
_this._promiseResult = value; | ||
this._promiseResult = value; | ||
innerResolve(value); | ||
_this._status = ExposedPromiseStatus.RESOLVED; | ||
this._status = ExposedPromiseStatus.RESOLVED; | ||
return; | ||
}; | ||
_this._reject = function (reason) { | ||
if (_this.isSettled()) { | ||
this._reject = (reason) => { | ||
if (this.isSettled()) { | ||
return; | ||
} | ||
_this._promiseError = reason; | ||
this._promiseError = reason; | ||
innerReject(reason); | ||
_this._status = ExposedPromiseStatus.REJECTED; | ||
this._status = ExposedPromiseStatus.REJECTED; | ||
return; | ||
@@ -45,69 +62,26 @@ }; | ||
} | ||
Object.defineProperty(ExposedPromise.prototype, "promise", { | ||
get: function () { | ||
return this._promise; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ExposedPromise.prototype, "resolve", { | ||
get: function () { | ||
return this._resolve; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ExposedPromise.prototype, "reject", { | ||
get: function () { | ||
return this._reject; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ExposedPromise.prototype, "status", { | ||
get: function () { | ||
return this._status; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ExposedPromise.prototype, "promiseResult", { | ||
get: function () { | ||
return this._promiseResult; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ExposedPromise.prototype, "promiseError", { | ||
get: function () { | ||
return this._promiseError; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
ExposedPromise.resolve = function (value) { | ||
var promise = new ExposedPromise(); | ||
static resolve(value) { | ||
const promise = new ExposedPromise(); | ||
promise.resolve(value); | ||
return promise; | ||
}; | ||
ExposedPromise.reject = function (reason) { | ||
var promise = new ExposedPromise(); | ||
} | ||
static reject(reason) { | ||
const promise = new ExposedPromise(); | ||
promise.reject(reason); | ||
return promise; | ||
}; | ||
ExposedPromise.prototype.isPending = function () { | ||
} | ||
isPending() { | ||
return this.status === ExposedPromiseStatus.PENDING; | ||
}; | ||
ExposedPromise.prototype.isResolved = function () { | ||
} | ||
isResolved() { | ||
return this.status === ExposedPromiseStatus.RESOLVED; | ||
}; | ||
ExposedPromise.prototype.isRejected = function () { | ||
} | ||
isRejected() { | ||
return this.status === ExposedPromiseStatus.REJECTED; | ||
}; | ||
ExposedPromise.prototype.isSettled = function () { | ||
} | ||
isSettled() { | ||
return this.isResolved() || this.isRejected(); | ||
}; | ||
return ExposedPromise; | ||
}()); | ||
} | ||
} | ||
exports.ExposedPromise = ExposedPromise; | ||
//# sourceMappingURL=exposed-promise.js.map |
@@ -11,33 +11,6 @@ "use strict"; | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateGUID = void 0; | ||
/* eslint-disable prefer-arrow/prefer-arrow-functions */ | ||
var random_1 = require("@stablelib/random"); | ||
const random_1 = require("@stablelib/random"); | ||
/** | ||
@@ -47,12 +20,9 @@ * Generate a random GUID | ||
function generateGUID() { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var buf; | ||
return __generator(this, function (_a) { | ||
buf = (0, random_1.randomBytes)(16); | ||
return [2 /*return*/, [buf.slice(0, 4), buf.slice(4, 6), buf.slice(6, 8), buf.slice(8, 10), buf.slice(10, 16)] | ||
.map(function (subbuf) { | ||
return Buffer.from(subbuf).toString('hex'); | ||
}) | ||
.join('-')]; | ||
}); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const buf = (0, random_1.randomBytes)(16); | ||
return [buf.slice(0, 4), buf.slice(4, 6), buf.slice(6, 8), buf.slice(8, 10), buf.slice(10, 16)] | ||
.map(function (subbuf) { | ||
return Buffer.from(subbuf).toString('hex'); | ||
}) | ||
.join('-'); | ||
}); | ||
@@ -59,0 +29,0 @@ } |
export { keys } from './utils/keys'; | ||
export { ExposedPromise, ExposedPromiseStatus } from './utils/exposed-promise'; | ||
export { getKeypairFromSeed, toHex, getAddressFromPublicKey, decryptCryptoboxPayload, encryptCryptoboxPayload, getHexHash, sealCryptobox, openCryptobox, recipientString, signMessage, prefixPublicKey } from './utils/crypto'; | ||
export { getKeypairFromSeed, toHex, getAddressFromPublicKey, decryptCryptoboxPayload, encryptCryptoboxPayload, getHexHash, sealCryptobox, openCryptobox, recipientString, signMessage, isValidAddress, prefixPublicKey } from './utils/crypto'; | ||
export { generateGUID } from './utils/generate-uuid'; | ||
export declare const CONTRACT_PREFIX = "KT1"; | ||
export declare const secretbox_NONCEBYTES = 24; | ||
export declare const secretbox_MACBYTES = 16; |
export { keys } from './utils/keys'; | ||
export { ExposedPromise, ExposedPromiseStatus } from './utils/exposed-promise'; | ||
export { getKeypairFromSeed, toHex, getAddressFromPublicKey, decryptCryptoboxPayload, encryptCryptoboxPayload, getHexHash, sealCryptobox, openCryptobox, recipientString, signMessage, prefixPublicKey } from './utils/crypto'; | ||
export { getKeypairFromSeed, toHex, getAddressFromPublicKey, decryptCryptoboxPayload, encryptCryptoboxPayload, getHexHash, sealCryptobox, openCryptobox, recipientString, signMessage, isValidAddress, prefixPublicKey } from './utils/crypto'; | ||
export { generateGUID } from './utils/generate-uuid'; | ||
export const CONTRACT_PREFIX = 'KT1'; | ||
export const secretbox_NONCEBYTES = 24; // crypto_secretbox_NONCEBYTES | ||
export const secretbox_MACBYTES = 16; // crypto_secretbox_MACBYTES | ||
//# sourceMappingURL=index.js.map |
@@ -74,1 +74,2 @@ /// <reference types="node" /> | ||
}) => Promise<string>; | ||
export declare const isValidAddress: (address: string) => 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'; | ||
@@ -37,9 +28,7 @@ import { box, generateKeyPair, openBox, openSecretBox, secretBox } from '@stablelib/nacl'; | ||
*/ | ||
export function getHexHash(key) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (typeof key === 'string') { | ||
return toHex(hash(encode(key), 32)); | ||
} | ||
return toHex(hash(key, 32)); | ||
}); | ||
export async function getHexHash(key) { | ||
if (typeof key === 'string') { | ||
return toHex(hash(encode(key), 32)); | ||
} | ||
return toHex(hash(key, 32)); | ||
} | ||
@@ -51,6 +40,4 @@ /** | ||
*/ | ||
export function getKeypairFromSeed(seed) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return generateKeyPairFromSeed(hash(encode(seed), 32)); | ||
}); | ||
export async function getKeypairFromSeed(seed) { | ||
return generateKeyPairFromSeed(hash(encode(seed), 32)); | ||
} | ||
@@ -63,11 +50,9 @@ /** | ||
*/ | ||
export function encryptCryptoboxPayload(message, sharedKey) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const nonce = Buffer.from(randomBytes(secretbox_NONCEBYTES)); | ||
const combinedPayload = Buffer.concat([ | ||
nonce, | ||
Buffer.from(secretBox(sharedKey, nonce, Buffer.from(message, 'utf8'))) | ||
]); | ||
return toHex(combinedPayload); | ||
}); | ||
export async function encryptCryptoboxPayload(message, sharedKey) { | ||
const nonce = Buffer.from(randomBytes(secretbox_NONCEBYTES)); | ||
const combinedPayload = Buffer.concat([ | ||
nonce, | ||
Buffer.from(secretBox(sharedKey, nonce, Buffer.from(message, 'utf8'))) | ||
]); | ||
return toHex(combinedPayload); | ||
} | ||
@@ -80,12 +65,10 @@ /** | ||
*/ | ||
export function decryptCryptoboxPayload(payload, sharedKey) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const nonce = payload.slice(0, secretbox_NONCEBYTES); | ||
const ciphertext = payload.slice(secretbox_NONCEBYTES); | ||
const openBox = openSecretBox(sharedKey, nonce, ciphertext); | ||
if (!openBox) { | ||
throw new Error('Decryption failed'); | ||
} | ||
return Buffer.from(openBox).toString('utf8'); | ||
}); | ||
export async function decryptCryptoboxPayload(payload, sharedKey) { | ||
const nonce = payload.slice(0, secretbox_NONCEBYTES); | ||
const ciphertext = payload.slice(secretbox_NONCEBYTES); | ||
const openBox = openSecretBox(sharedKey, nonce, ciphertext); | ||
if (!openBox) { | ||
throw new Error('Decryption failed'); | ||
} | ||
return Buffer.from(openBox).toString('utf8'); | ||
} | ||
@@ -98,12 +81,10 @@ /** | ||
*/ | ||
export function sealCryptobox(payload, otherPublicKey) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const kxOtherPublicKey = convertPublicKeyToX25519(Buffer.from(otherPublicKey)); // Secret bytes to scalar bytes | ||
const keypair = generateKeyPair(); | ||
const state = new BLAKE2b(24); | ||
const nonce = state.update(keypair.publicKey, 32).update(kxOtherPublicKey, 32).digest(); | ||
const bytesPayload = typeof payload === 'string' ? encode(payload) : payload; | ||
const encryptedMessage = box(kxOtherPublicKey, keypair.secretKey, nonce, bytesPayload); | ||
return toHex(concat(keypair.publicKey, encryptedMessage)); | ||
}); | ||
export async function sealCryptobox(payload, otherPublicKey) { | ||
const kxOtherPublicKey = convertPublicKeyToX25519(Buffer.from(otherPublicKey)); // Secret bytes to scalar bytes | ||
const keypair = generateKeyPair(); | ||
const state = new BLAKE2b(24); | ||
const nonce = state.update(keypair.publicKey, 32).update(kxOtherPublicKey, 32).digest(); | ||
const bytesPayload = typeof payload === 'string' ? encode(payload) : payload; | ||
const encryptedMessage = box(kxOtherPublicKey, keypair.secretKey, nonce, bytesPayload); | ||
return toHex(concat(keypair.publicKey, encryptedMessage)); | ||
} | ||
@@ -117,17 +98,15 @@ /** | ||
*/ | ||
export function openCryptobox(encryptedPayload, publicKey, privateKey) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const kxSelfPrivateKey = convertSecretKeyToX25519(Buffer.from(privateKey)); // Secret bytes to scalar bytes | ||
const kxSelfPublicKey = convertPublicKeyToX25519(Buffer.from(publicKey)); // Secret bytes to scalar bytes | ||
const bytesPayload = typeof encryptedPayload === 'string' ? encode(encryptedPayload) : encryptedPayload; | ||
const epk = bytesPayload.slice(0, 32); | ||
const ciphertext = bytesPayload.slice(32); | ||
const state = new BLAKE2b(24); | ||
const nonce = state.update(epk, 32).update(kxSelfPublicKey, 32).digest(); | ||
const decryptedMessage2 = openBox(epk, kxSelfPrivateKey, nonce, ciphertext); | ||
if (!decryptedMessage2) { | ||
throw new Error('Decryption failed'); | ||
} | ||
return Buffer.from(decryptedMessage2).toString(); | ||
}); | ||
export async function openCryptobox(encryptedPayload, publicKey, privateKey) { | ||
const kxSelfPrivateKey = convertSecretKeyToX25519(Buffer.from(privateKey)); // Secret bytes to scalar bytes | ||
const kxSelfPublicKey = convertPublicKeyToX25519(Buffer.from(publicKey)); // Secret bytes to scalar bytes | ||
const bytesPayload = typeof encryptedPayload === 'string' ? encode(encryptedPayload) : encryptedPayload; | ||
const epk = bytesPayload.slice(0, 32); | ||
const ciphertext = bytesPayload.slice(32); | ||
const state = new BLAKE2b(24); | ||
const nonce = state.update(epk, 32).update(kxSelfPublicKey, 32).digest(); | ||
const decryptedMessage2 = openBox(epk, kxSelfPrivateKey, nonce, ciphertext); | ||
if (!decryptedMessage2) { | ||
throw new Error('Decryption failed'); | ||
} | ||
return Buffer.from(decryptedMessage2).toString(); | ||
} | ||
@@ -139,45 +118,43 @@ /** | ||
*/ | ||
export function getAddressFromPublicKey(publicKey) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
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) { | ||
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 = hash(Buffer.from(plainPublicKey, 'hex'), 20); | ||
return bs58check.encode(Buffer.concat([prefix, Buffer.from(payload)])); | ||
}); | ||
} | ||
if (!prefix || !plainPublicKey) { | ||
throw new Error(`invalid publicKey: ${publicKey}`); | ||
} | ||
const payload = hash(Buffer.from(plainPublicKey, 'hex'), 20); | ||
return bs58check.encode(Buffer.concat([prefix, Buffer.from(payload)])); | ||
} | ||
@@ -189,10 +166,8 @@ /** | ||
*/ | ||
export function prefixPublicKey(publicKey) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (publicKey.length !== 64) { | ||
return publicKey; | ||
} | ||
const payload = Buffer.from(publicKey, 'hex'); | ||
return bs58check.encode(Buffer.concat([new Uint8Array([13, 15, 37, 217]), Buffer.from(payload)])); | ||
}); | ||
export async function prefixPublicKey(publicKey) { | ||
if (publicKey.length !== 64) { | ||
return publicKey; | ||
} | ||
const payload = Buffer.from(publicKey, 'hex'); | ||
return bs58check.encode(Buffer.concat([new Uint8Array([13, 15, 37, 217]), Buffer.from(payload)])); | ||
} | ||
@@ -208,3 +183,3 @@ /** | ||
} | ||
const toBuffer = (message) => __awaiter(void 0, void 0, void 0, function* () { | ||
const toBuffer = async (message) => { | ||
if (message.length % 2 !== 0) { | ||
@@ -222,15 +197,28 @@ return encode(message); | ||
return encode(message); | ||
}); | ||
const coinlibhash = (message, size = 32) => __awaiter(void 0, void 0, void 0, function* () { | ||
}; | ||
const coinlibhash = async (message, size = 32) => { | ||
return hash(message, size); | ||
}); | ||
export const signMessage = (message, keypair) => __awaiter(void 0, void 0, void 0, function* () { | ||
const bufferMessage = yield toBuffer(message); | ||
}; | ||
export const signMessage = async (message, keypair) => { | ||
const bufferMessage = await toBuffer(message); | ||
const edsigPrefix = new Uint8Array([9, 245, 205, 134, 18]); | ||
const hash = yield coinlibhash(bufferMessage); | ||
const hash = await coinlibhash(bufferMessage); | ||
const rawSignature = sign(keypair.secretKey, hash); | ||
const signature = bs58check.encode(Buffer.concat([Buffer.from(edsigPrefix), Buffer.from(rawSignature)])); | ||
return signature; | ||
}); | ||
}; | ||
export const isValidAddress = (address) => { | ||
const prefixes = ['tz1', 'tz2', 'tz3', 'tz4', 'KT1', 'txr1', 'sr1']; | ||
if (!prefixes.some((p) => address.toLowerCase().startsWith(p.toLowerCase()))) { | ||
return false; | ||
} | ||
try { | ||
bs58check.decode(address); | ||
} | ||
catch (error) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
/* eslint-enable prefer-arrow/prefer-arrow-functions */ | ||
//# sourceMappingURL=crypto.js.map |
@@ -6,4 +6,4 @@ export declare enum ExposedPromiseStatus { | ||
} | ||
declare type Resolve<T> = (value: T) => void; | ||
declare type Reject<U> = (reason?: U) => void; | ||
type Resolve<T> = (value: T) => void; | ||
type Reject<U> = (reason?: U) => void; | ||
/** | ||
@@ -10,0 +10,0 @@ * Exposed promise allow you to create a promise and then resolve it later, from the outside |
@@ -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(); |
@@ -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()); | ||
}); | ||
}; | ||
/* eslint-disable prefer-arrow/prefer-arrow-functions */ | ||
@@ -15,13 +6,11 @@ import { randomBytes } from '@stablelib/random'; | ||
*/ | ||
export function generateGUID() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const buf = randomBytes(16); | ||
return [buf.slice(0, 4), buf.slice(4, 6), buf.slice(6, 8), buf.slice(8, 10), buf.slice(10, 16)] | ||
.map(function (subbuf) { | ||
return Buffer.from(subbuf).toString('hex'); | ||
}) | ||
.join('-'); | ||
}); | ||
export async function generateGUID() { | ||
const buf = randomBytes(16); | ||
return [buf.slice(0, 4), buf.slice(4, 6), buf.slice(6, 8), buf.slice(8, 10), buf.slice(10, 16)] | ||
.map(function (subbuf) { | ||
return Buffer.from(subbuf).toString('hex'); | ||
}) | ||
.join('-'); | ||
} | ||
/* eslint-enable prefer-arrow/prefer-arrow-functions */ | ||
//# sourceMappingURL=generate-uuid.js.map |
{ | ||
"name": "@airgap/beacon-utils", | ||
"version": "4.0.12", | ||
"version": "4.0.13-beta.0", | ||
"description": "This package contains utility functions that are used throughout the beacon-sdk", | ||
@@ -38,3 +38,3 @@ "author": "Andreas Gassmann <a.gassmann@papers.ch>", | ||
"@stablelib/ed25519": "^1.0.3", | ||
"@stablelib/nacl": "^1.0.3", | ||
"@stablelib/nacl": "^1.0.4", | ||
"@stablelib/random": "^1.0.2", | ||
@@ -44,3 +44,3 @@ "@stablelib/utf8": "^1.0.1", | ||
}, | ||
"gitHead": "9bd66991f2424a9bdfe458d264ee08ba8b8086ab" | ||
"gitHead": "2f8536539484b7a667d7677a67fdb76cf2250e49" | ||
} |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
60064
977
1
Updated@stablelib/nacl@^1.0.4