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

@mysten/enoki

Package Overview
Dependencies
Maintainers
4
Versions
189
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mysten/enoki - npm Package Compare versions

Comparing version 0.0.0-experimental-20231121172842 to 0.0.0-experimental-20231121174042

7

CHANGELOG.md
# @mysten/enoki
## 0.0.0-experimental-20231121172842
## 0.0.0-experimental-20231121174042
### Patch Changes
- 180616bef: Rewrite the encryption layer
- 9ac7e2f3d: Introduce Enoki SDK

@@ -12,3 +13,3 @@ - Updated dependencies [194c980cb]

- Updated dependencies [64d45ba27]
- @mysten/sui.js@0.0.0-experimental-20231121172842
- @mysten/zklogin@0.0.0-experimental-20231121172842
- @mysten/sui.js@0.0.0-experimental-20231121174042
- @mysten/zklogin@0.0.0-experimental-20231121174042

@@ -25,11 +25,60 @@ "use strict";

module.exports = __toCommonJS(encryption_exports);
var import_browser_passworder = require("@metamask/browser-passworder");
var import_utils = require("@mysten/sui.js/utils");
function createDefaultEncryption() {
async function keyFromPassword(password, salt) {
const key = await crypto.subtle.importKey(
"raw",
new TextEncoder().encode(password),
{ name: "PBKDF2" },
false,
["deriveBits", "deriveKey"]
);
const derivedKey = await crypto.subtle.deriveKey(
{
name: "PBKDF2",
salt,
iterations: 9e5,
hash: "SHA-256"
},
key,
{ name: "AES-GCM", length: 256 },
false,
["encrypt", "decrypt"]
);
return { key, derivedKey };
}
return {
async encrypt(password, data) {
return (0, import_browser_passworder.encrypt)(password, data);
const salt = crypto.getRandomValues(new Uint8Array(16));
const iv = crypto.getRandomValues(new Uint8Array(12));
const { derivedKey } = await keyFromPassword(password, salt);
const payload = await crypto.subtle.encrypt(
{
name: "AES-GCM",
iv
},
derivedKey,
new TextEncoder().encode(data)
);
return JSON.stringify({
payload: (0, import_utils.toB64)(new Uint8Array(payload)),
iv: (0, import_utils.toB64)(iv),
salt: (0, import_utils.toB64)(salt)
});
},
async decrypt(password, data) {
const decrypted = await (0, import_browser_passworder.decrypt)(password, data);
return decrypted;
const parsed = JSON.parse(data);
if (!parsed.payload || !parsed.iv || !parsed.salt) {
throw new Error("Invalid encrypted data");
}
const { derivedKey } = await keyFromPassword(password, (0, import_utils.fromB64)(parsed.salt));
const decryptedContent = await crypto.subtle.decrypt(
{
name: "AES-GCM",
iv: (0, import_utils.fromB64)(parsed.iv)
},
derivedKey,
(0, import_utils.fromB64)(parsed.payload)
);
return new TextDecoder().decode(decryptedContent);
}

@@ -36,0 +85,0 @@ };

@@ -1,13 +0,59 @@

import {
decrypt as metamaskDecrypt,
encrypt as metamaskEncrypt
} from "@metamask/browser-passworder";
import { fromB64, toB64 } from "@mysten/sui.js/utils";
function createDefaultEncryption() {
async function keyFromPassword(password, salt) {
const key = await crypto.subtle.importKey(
"raw",
new TextEncoder().encode(password),
{ name: "PBKDF2" },
false,
["deriveBits", "deriveKey"]
);
const derivedKey = await crypto.subtle.deriveKey(
{
name: "PBKDF2",
salt,
iterations: 9e5,
hash: "SHA-256"
},
key,
{ name: "AES-GCM", length: 256 },
false,
["encrypt", "decrypt"]
);
return { key, derivedKey };
}
return {
async encrypt(password, data) {
return metamaskEncrypt(password, data);
const salt = crypto.getRandomValues(new Uint8Array(16));
const iv = crypto.getRandomValues(new Uint8Array(12));
const { derivedKey } = await keyFromPassword(password, salt);
const payload = await crypto.subtle.encrypt(
{
name: "AES-GCM",
iv
},
derivedKey,
new TextEncoder().encode(data)
);
return JSON.stringify({
payload: toB64(new Uint8Array(payload)),
iv: toB64(iv),
salt: toB64(salt)
});
},
async decrypt(password, data) {
const decrypted = await metamaskDecrypt(password, data);
return decrypted;
const parsed = JSON.parse(data);
if (!parsed.payload || !parsed.iv || !parsed.salt) {
throw new Error("Invalid encrypted data");
}
const { derivedKey } = await keyFromPassword(password, fromB64(parsed.salt));
const decryptedContent = await crypto.subtle.decrypt(
{
name: "AES-GCM",
iv: fromB64(parsed.iv)
},
derivedKey,
fromB64(parsed.payload)
);
return new TextDecoder().decode(decryptedContent);
}

@@ -14,0 +60,0 @@ };

{
"name": "@mysten/enoki",
"version": "0.0.0-experimental-20231121172842",
"version": "0.0.0-experimental-20231121174042",
"description": "TODO: Description",

@@ -44,8 +44,7 @@ "license": "Apache-2.0",

"dependencies": {
"@metamask/browser-passworder": "^4.1.0",
"@nanostores/react": "^0.7.1",
"jose": "^4.14.4",
"nanostores": "^0.9.3",
"@mysten/sui.js": "0.0.0-experimental-20231121172842",
"@mysten/zklogin": "0.0.0-experimental-20231121172842"
"@mysten/sui.js": "0.0.0-experimental-20231121174042",
"@mysten/zklogin": "0.0.0-experimental-20231121174042"
},

@@ -52,0 +51,0 @@ "peerDependencies": {

// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import {
decrypt as metamaskDecrypt,
encrypt as metamaskEncrypt,
} from '@metamask/browser-passworder';
import { fromB64, toB64 } from '@mysten/sui.js/utils';

@@ -21,9 +18,73 @@ /**

export function createDefaultEncryption(): Encryption {
type EncryptedJSON = {
payload: string;
iv: string;
salt: string;
};
async function keyFromPassword(password: string, salt: Uint8Array) {
const key = await crypto.subtle.importKey(
'raw',
new TextEncoder().encode(password),
{ name: 'PBKDF2' },
false,
['deriveBits', 'deriveKey'],
);
const derivedKey = await crypto.subtle.deriveKey(
{
name: 'PBKDF2',
salt,
iterations: 900_000,
hash: 'SHA-256',
},
key,
{ name: 'AES-GCM', length: 256 },
false,
['encrypt', 'decrypt'],
);
return { key, derivedKey };
}
return {
async encrypt(password, data) {
return metamaskEncrypt(password, data);
const salt = crypto.getRandomValues(new Uint8Array(16));
const iv = crypto.getRandomValues(new Uint8Array(12));
const { derivedKey } = await keyFromPassword(password, salt);
const payload = await crypto.subtle.encrypt(
{
name: 'AES-GCM',
iv,
},
derivedKey,
new TextEncoder().encode(data),
);
return JSON.stringify({
payload: toB64(new Uint8Array(payload)),
iv: toB64(iv),
salt: toB64(salt),
} satisfies EncryptedJSON);
},
async decrypt(password, data) {
const decrypted = await metamaskDecrypt(password, data);
return decrypted as string;
const parsed = JSON.parse(data) as EncryptedJSON;
if (!parsed.payload || !parsed.iv || !parsed.salt) {
throw new Error('Invalid encrypted data');
}
const { derivedKey } = await keyFromPassword(password, fromB64(parsed.salt));
const decryptedContent = await crypto.subtle.decrypt(
{
name: 'AES-GCM',
iv: fromB64(parsed.iv),
},
derivedKey,
fromB64(parsed.payload),
);
return new TextDecoder().decode(decryptedContent);
},

@@ -30,0 +91,0 @@ };

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