Skip to content

Commit

Permalink
Update everything to @nimiq/core@next
Browse files Browse the repository at this point in the history
sisou committed Nov 15, 2024
1 parent 3eca28c commit ef77f72
Showing 91 changed files with 464 additions and 293 deletions.
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
},
"homepage": "https://github.com/nimiq/keyguard/client#readme",
"dependencies": {
"@nimiq/core-web": "1.6.3",
"@nimiq/albatross-wasm": "npm:@nimiq/core@next",
"@nimiq/rpc": "^0.3.0",
"@opengsn/common": "^2.2.5"
},
2 changes: 1 addition & 1 deletion client/src/Observable.ts
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ export default class Observable {
this._listeners = new Map();
}

public on<T>(type: string, callback: (arg: T) => any): number {
public on(type: string, callback: (...args: any[]) => any): number {
if (!this._listeners.has(type)) {
this._listeners.set(type, [callback]);
return 0;
9 changes: 5 additions & 4 deletions client/src/PublicRequest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Nimiq from '@nimiq/core-web';
import * as Nimiq from '@nimiq/albatross-wasm';
import { ForwardRequest as OpenGsnForwardRequest } from '@opengsn/common/dist/EIP712/ForwardRequest';
import { RelayData as OpenGsnRelayData } from '@opengsn/common/dist/EIP712/RelayData';
import { KeyguardCommand } from './KeyguardCommand';
@@ -43,13 +43,14 @@ export type TransactionInfo = {
keyPath: string,
senderLabel?: string,
sender: Uint8Array,
senderType: Nimiq.Account.Type | 3,
senderType: Nimiq.AccountType,
senderData?: Uint8Array,
recipient: Uint8Array,
recipientType?: Nimiq.Account.Type,
recipientType?: Nimiq.AccountType,
recipientData?: Uint8Array,
value: number,
fee: number,
validityStartHeight: number,
data?: Uint8Array,
flags?: number,
};

30 changes: 25 additions & 5 deletions client/yarn.lock
Original file line number Diff line number Diff line change
@@ -211,10 +211,13 @@
"@ethersproject/properties" "^5.7.0"
"@ethersproject/strings" "^5.7.0"

"@nimiq/core-web@1.6.3":
version "1.6.3"
resolved "https://registry.yarnpkg.com/@nimiq/core-web/-/core-web-1.6.3.tgz#b4a8f8c5d289850b20cb4009766af5b1cafd6e20"
integrity sha512-D6RrJi2cRU81odNpmwczhUBvOQ47+/Db1svrTkH/G4xNd72lr9MS5nMdfpUz+rBRnSprljrzW2mdUtZ6W9bPaA==
"@nimiq/albatross-wasm@npm:@nimiq/core@next":
version "2.0.0-next.rc.4"
resolved "https://registry.yarnpkg.com/@nimiq/core/-/core-2.0.0-next.rc.4.tgz#a353f4507f2f10e3be741f920cff921c9474dea7"
integrity sha512-qSBy/Mg0rbqAstEnrgzGhqeQpmQdOjCZPWmBV5uFxAMAAYl9nrABaXWQXo3Jvemvx5VQE9pz5/ma3I8Z0ROy1g==
dependencies:
comlink "^4.4.1"
websocket "^1.0.34"

"@nimiq/rpc@^0.3.0":
version "0.3.0"
@@ -850,6 +853,11 @@ combined-stream@^1.0.6, combined-stream@~1.0.6:
dependencies:
delayed-stream "~1.0.0"

comlink@^4.4.1:
version "4.4.2"
resolved "https://registry.yarnpkg.com/comlink/-/comlink-4.4.2.tgz#cbbcd82742fbebc06489c28a183eedc5c60a2bca"
integrity sha512-OxGdvBmJuNKSCMO4NTl1L47VRp6xn2wG4F/2hYzB6tiCb709otOxtEYCSvK80PtjODfXXZu8ds+Nw5kVCjqd2g==

commander@^2.12.1:
version "2.17.1"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.17.1.tgz#bd77ab7de6de94205ceacc72f1716d29f20a77bf"
@@ -1149,7 +1157,7 @@ es-errors@^1.3.0:
resolved "https://registry.yarnpkg.com/es-errors/-/es-errors-1.3.0.tgz#05f75a25dab98e4fb1dcd5e1472c0546d5057c8f"
integrity sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==

es5-ext@^0.10.35, es5-ext@^0.10.50, es5-ext@^0.10.62, es5-ext@~0.10.14:
es5-ext@^0.10.35, es5-ext@^0.10.50, es5-ext@^0.10.62, es5-ext@^0.10.63, es5-ext@~0.10.14:
version "0.10.64"
resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.64.tgz#12e4ffb48f1ba2ea777f1fcdd1918ef73ea21714"
integrity sha512-p2snDhiLaXe6dahss1LddxqEm+SkuDvV8dnIQG0MWjyHpcMNfXKPE+/Cc0y+PhxJX3A4xGNeFCj5oc0BUh6deg==
@@ -3447,6 +3455,18 @@ websocket@^1.0.32:
utf-8-validate "^5.0.2"
yaeti "^0.0.6"

websocket@^1.0.34:
version "1.0.35"
resolved "https://registry.yarnpkg.com/websocket/-/websocket-1.0.35.tgz#374197207d7d4cc4c36cbf8a1bb886ee52a07885"
integrity sha512-/REy6amwPZl44DDzvRCkaI1q1bIiQB0mEFQLUrhz3z2EK91cp3n72rAjUlrTP0zV22HJIUOVHQGPxhFRjxjt+Q==
dependencies:
bufferutil "^4.0.1"
debug "^2.2.0"
es5-ext "^0.10.63"
typedarray-to-buffer "^3.1.5"
utf-8-validate "^5.0.2"
yaeti "^0.0.6"

whatwg-url@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
4 changes: 2 additions & 2 deletions demos/DerivePolygonAddress.html
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<title>Derive Polygon Address | Keyguard Demo</title>
<link href="../src/nimiq-style.css" rel="stylesheet">
<script src="../node_modules/@nimiq/core-web/web-offline.js"></script>
<script src="../src/lib/AlbatrossWasm.mjs" type="module"></script>
<script src="../src/lib/Constants.js"></script>
<script src="../src/lib/Key.js"></script>
<script src="../src/lib/KeyStore.js"></script>
@@ -33,7 +33,7 @@

const secret = Nimiq.Entropy.generate();
const key = new Key(secret);
const password = Nimiq.BufferUtils.fromAscii('1234567890');
const password = Nimiq.BufferUtils.fromUtf8('1234567890');
const id = await KeyStore.instance.put(key, password);

const request = {
6 changes: 3 additions & 3 deletions demos/Export.html
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
</head>
<body>
<link href="../src/nimiq-style.css" rel="stylesheet">
<script src="../node_modules/@nimiq/core-web/web-offline.js"></script>
<script src="../src/lib/AlbatrossWasm.mjs" type="module"></script>
<script src="../src/lib/Constants.js"></script>
<script src="../src/lib/Key.js"></script>
<script src="../src/lib/KeyStore.js"></script>
@@ -30,7 +30,7 @@
document.querySelector('.bip39').addEventListener('click', async () => {
const entropy = Nimiq.Entropy.generate();
const key = new Key(entropy);
const password = Nimiq.BufferUtils.fromAscii('1234567890');
const password = Nimiq.BufferUtils.fromUtf8('1234567890');
const id = await KeyStore.instance.put(key, password);

const exportRequest = {
@@ -44,7 +44,7 @@
document.querySelector('.legacy').addEventListener('click', async () => {
const secret = Nimiq.PrivateKey.generate();
const key = new Key(secret);
const password = Nimiq.BufferUtils.fromAscii('1234567890');
const password = Nimiq.BufferUtils.fromUtf8('1234567890');
const id = await KeyStore.instance.put(key, password);

const exportRequest = {
2 changes: 1 addition & 1 deletion demos/LanguagePicker.html
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>i18n Test | Keyguard Demo</title>
<script src="../node_modules/@nimiq/core-web/web-offline.js"></script>
<script src="../src/lib/AlbatrossWasm.mjs" type="module"></script>
<script src="../src/lib/I18n.js"></script>
<script src="../src/components/LanguagePicker.js"></script>
<style>
2 changes: 1 addition & 1 deletion demos/LoginFile.html
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
font-src 'self';">
<title>Login File | Keyguard Demo</title>

<script src="../node_modules/@nimiq/core-web/web-offline.js"></script>
<script src="../src/lib/AlbatrossWasm.mjs" type="module"></script>
<script src="../src/lib/Iqons.js"></script>
<script src="../src/lib/QrEncoder.js"></script>
<script src="../src/lib/LoginFileConfig.js"></script>
2 changes: 1 addition & 1 deletion demos/PasswordInput.html
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ <h2>Password Getter</h2>
<link href="../src/components/PasswordInput.css" rel="stylesheet">
<link href="../src/components/PasswordBox.css" rel="stylesheet">

<script type="text/javascript" src="../node_modules/@nimiq/core-web/web-offline.js"></script>
<script type="module" src="../src/lib/AlbatrossWasm.mjs"></script>
<script type="text/javascript" src="../src/lib/TemplateTags.js"></script>
<script type="text/javascript" src="../src/lib/I18n.js"></script>
<script type="text/javascript" src="../src/translations/index.js"></script>
4 changes: 2 additions & 2 deletions demos/RemoveKey.html
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<title>Remove Key | Keyguard Demo</title>
<link href="../src/nimiq-style.css" rel="stylesheet">
<script src="../node_modules/@nimiq/core-web/web-offline.js"></script>
<script src="../src/lib/AlbatrossWasm.mjs" type="module"></script>
<script src="../src/lib/Constants.js"></script>
<script src="../src/lib/Key.js"></script>
<script src="../src/lib/KeyStore.js"></script>
@@ -30,7 +30,7 @@

const secret = Nimiq.Entropy.generate();
const key = new Key(secret);
const password = Nimiq.BufferUtils.fromAscii('1234567890');
const password = Nimiq.BufferUtils.fromUtf8('1234567890');
const id = await KeyStore.instance.put(key, password);

const removeRequest = {
4 changes: 2 additions & 2 deletions demos/SignTransaction.html
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<title>SignTransaction | Keyguard Demo</title>
<link href="../src/nimiq-style.css" rel="stylesheet">
<script src="../node_modules/@nimiq/core-web/web-offline.js"></script>
<script src="../src/lib/AlbatrossWasm.mjs" type="module"></script>
<script src="../src/lib/Constants.js"></script>
<script src="../src/lib/Key.js"></script>
<script src="../src/lib/KeyStore.js"></script>
@@ -135,7 +135,7 @@
// Generate a random key and put it into the KeyStore.
const secret = Nimiq.Entropy.generate();
const key = new Key(secret);
const password = keyPassword ? Nimiq.BufferUtils.fromAscii(keyPassword) : undefined;
const password = keyPassword ? Nimiq.BufferUtils.fromUtf8(keyPassword) : undefined;
const id = await KeyStore.instance.put(key, password);

const path = "m/0'/0'";
2 changes: 1 addition & 1 deletion demos/setup.html
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>Demo SetUp</title>
<script src="../node_modules/@nimiq/core-web/web-offline.js"></script>
<script src="../src/lib/AlbatrossWasm.mjs" type="module"></script>
<script src="../src/lib/CookieJar.js"></script>
<script src="../src/lib/KeyInfo.js"></script>
<script src="../src/lib/KeyStore.js"></script>
5 changes: 1 addition & 4 deletions karma.conf.coverage.js
Original file line number Diff line number Diff line change
@@ -14,10 +14,7 @@ module.exports = function (/** @type {any} */ config) {

// list of files / patterns to load in the browser
files: [
'node_modules/@nimiq/core-web/web-offline.js',
{'pattern': 'node_modules/@nimiq/core-web/worker-wasm.wasm', included: false},
{'pattern': 'node_modules/@nimiq/core-web/worker-wasm.js', included: false},
{'pattern': 'node_modules/@nimiq/core-web/worker.js', included: false},
{'pattern': 'node_modules/@nimiq/albatross-wasm/**/*', included: false},
'instrumented/**/*js',
'tests/**/*.spec.js'
],
5 changes: 1 addition & 4 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -14,10 +14,7 @@ module.exports = function (/** @type {any} */ config) {

// list of files / patterns to load in the browser
files: [
'node_modules/@nimiq/core-web/web-offline.js',
{pattern: 'node_modules/@nimiq/core-web/worker-wasm.wasm', included: false},
{pattern: 'node_modules/@nimiq/core-web/worker-wasm.js', included: false},
{pattern: 'node_modules/@nimiq/core-web/worker.js', included: false},
{'pattern': 'node_modules/@nimiq/albatross-wasm/**/*', included: false},
'src/lib/*.js', // Force load of lib files before components and common.js
'src/request/TopLevelApi.js', // Force load of TopLevelApi before BitcoinEnabledTopLevelApi
'src/lib/bitcoin/*.js',
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
"lintfix": "eslint --fix src tools",
"checkdeps": "node tools/dependencyValidator.js",
"checklangs": "yarn i18n:build-dictionary && node tools/translationValidator.js",
"pr": "yarn typecheck && yarn lint && yarn test && yarn checkdeps && yarn checklangs && yarn build testnet && cd client && yarn lint && yarn build",
"pr": "yarn typecheck && yarn lint && yarn checkdeps && yarn checklangs && yarn build testnet && cd client && yarn lint && yarn build",
"watch": "tsc-watch --pretty --onSuccess \"yarn lint\"",
"watchfix": "tsc-watch --pretty --onSuccess \"yarn lintfix\"",
"postinstall": "cd client && yarn",
3 changes: 2 additions & 1 deletion serve.js
Original file line number Diff line number Diff line change
@@ -72,7 +72,8 @@ var http = require("http"),
'wmls' : 'text/vnd.wap.wmlscript',
'xsl' : 'text/xml',
'xml' : 'text/xml',
'svg' : 'image/svg+xml'
'svg' : 'image/svg+xml',
'wasm' : 'application/wasm',
};

http.createServer(function(request, response) {
51 changes: 10 additions & 41 deletions src/common.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* global Nimiq */
/* global RpcServer */
/* global Errors */
/* global Constants */
/* global CONFIG */

/**
@@ -12,9 +10,6 @@
/** @type {Promise<void>?} */
let __nimiqLoaded = null;

/** @type {Promise<void>?} */
let __albatrossLoaded = null;

if (navigator.serviceWorker) {
// Register service worker to strip cookie from requests.
// This is on a best-effort basis. Cookies might still be sent to the server, if the service worker is not activated
@@ -38,42 +33,13 @@ if (navigator.serviceWorker) {
async function loadNimiq() {
// eslint-disable-next-line no-return-assign
return __nimiqLoaded || (__nimiqLoaded = new Promise(async resolve => {
// Load web assembly encryption library into browser (if supported)
await Nimiq.WasmHelper.doImport();

switch (CONFIG.NETWORK) {
case Constants.NETWORK.DEV:
Nimiq.GenesisConfig.dev();
break;
case Constants.NETWORK.TEST:
Nimiq.GenesisConfig.test();
break;
case Constants.NETWORK.MAIN:
Nimiq.GenesisConfig.main();
break;
default:
throw new Errors.InvalidNetworkConfig();
}

resolve();
}));
}

/**
* Singleton promise
*
* @returns {Promise<void>}
*/
async function loadAlbatross() {
// eslint-disable-next-line no-return-assign
return __albatrossLoaded || (__albatrossLoaded = new Promise(async resolve => {
await Albatross.default(); // eslint-disable-line no-undef
await Nimiq.default(); // eslint-disable-line no-undef
resolve();
}));
}

/**
* @typedef {{loadNimiq: boolean, loadAlbatross: boolean, whitelist: string[]}} Options
* @typedef {{loadNimiq: boolean, whitelist: string[]}} Options
*/

/**
@@ -85,7 +51,6 @@ async function runKeyguard(RequestApiClass, opts) { // eslint-disable-line no-un
/** @type {Options} */
const defaultOptions = {
loadNimiq: true,
loadAlbatross: false,
whitelist: ['request'],
};

@@ -96,10 +61,6 @@ async function runKeyguard(RequestApiClass, opts) { // eslint-disable-line no-un
await loadNimiq();
}

if (options.loadAlbatross) {
await loadAlbatross();
}

// If user navigates back to loading screen, skip it
window.addEventListener('hashchange', () => {
if (window.location.hash === '') {
@@ -156,3 +117,11 @@ async function runKeyguard(RequestApiClass, opts) { // eslint-disable-line no-un
TopLevelApi.showNoRequestErrorPage(); // eslint-disable-line no-undef
}
}

/**
* @param {number} lunas
* @returns {number}
*/
function lunasToCoins(lunas) { // eslint-disable-line no-unused-vars
return lunas / 1e5;
}
36 changes: 36 additions & 0 deletions src/commonPoW.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* global NimiqPoW */
/* global CONFIG */
/* global Constants */
/* global Errors */

/** @type {Promise<void>?} */
let __nimiqPoWLoaded = null;

/**
* Singleton promise
*
* @returns {Promise<void>}
*/
async function loadNimiqPow() { // eslint-disable-line no-unused-vars
// eslint-disable-next-line no-return-assign
return __nimiqPoWLoaded || (__nimiqPoWLoaded = new Promise(async resolve => {
// Load web assembly encryption library into browser (if supported)
await NimiqPoW.WasmHelper.doImport();

switch (CONFIG.NETWORK) {
case Constants.NETWORK.DEV:
NimiqPoW.GenesisConfig.dev();
break;
case Constants.NETWORK.TEST:
NimiqPoW.GenesisConfig.test();
break;
case Constants.NETWORK.MAIN:
NimiqPoW.GenesisConfig.main();
break;
default:
throw new Errors.InvalidNetworkConfig();
}

resolve();
}));
}
Loading

0 comments on commit ef77f72

Please sign in to comment.