From 7f9bc4939c844fcd70a8af6807bbcbff26469f74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren?= Date: Tue, 10 Dec 2024 22:26:36 +0100 Subject: [PATCH] Always load local Nimiq build --- public/albatross/lib/index.d.ts | 358 ------------------ public/index.html | 14 +- src/components/staking/StakingGraphPage.vue | 4 +- src/components/staking/StakingInfoPage.vue | 8 +- .../staking/ValidatorDetailsOverlay.vue | 4 +- src/network.ts | 4 +- 6 files changed, 11 insertions(+), 381 deletions(-) delete mode 100644 public/albatross/lib/index.d.ts diff --git a/public/albatross/lib/index.d.ts b/public/albatross/lib/index.d.ts deleted file mode 100644 index bdcb53a10..000000000 --- a/public/albatross/lib/index.d.ts +++ /dev/null @@ -1,358 +0,0 @@ -import { PrivateKey, Address } from '..'; - -declare class ArrayUtils { - static subarray(uintarr: Uint8Array, begin?: number, end?: number): Uint8Array; -} - -declare class SerialBuffer extends Uint8Array { - private _view; - private _readPos; - private _writePos; - static EMPTY: SerialBuffer; - constructor(length: number); - constructor(array: ArrayLike | ArrayBufferLike); - subarray(start?: number, end?: number): Uint8Array; - get readPos(): number; - set readPos(value: number); - get writePos(): number; - set writePos(value: number); - /** - * Resets the read and write position of the buffer to zero. - */ - reset(): void; - read(length: number): Uint8Array; - write(array: Uint8Array): void; - readUint8(): number; - writeUint8(value: number): void; - readUint16(): number; - writeUint16(value: number): void; - readUint32(): number; - writeUint32(value: number): void; - readUint64(): number; - writeUint64(value: number): void; - readVarUint(): number; - writeVarUint(value: number): void; - static varUintSize(value: number): number; - readFloat64(): number; - writeFloat64(value: number): void; - readString(length: number): string; - writeString(value: string, length: number): void; - readPaddedString(length: number): string; - writePaddedString(value: string, length: number): void; - readVarLengthString(): string; - writeVarLengthString(value: string): void; - static varLengthStringSize(value: string): number; -} - -type TypedArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array; -declare class BufferUtils { - static BASE64_ALPHABET: string; - static BASE32_ALPHABET: { - RFC4648: string; - RFC4648_HEX: string; - NIMIQ: string; - }; - static HEX_ALPHABET: string; - static _BASE64_LOOKUP: string[]; - private static _ISO_8859_15_DECODER?; - private static _UTF8_DECODER?; - private static _UTF8_ENCODER?; - static _codePointTextDecoder(buffer: Uint8Array): string; - static _tripletToBase64(num: number): string; - static _base64encodeChunk(u8: Uint8Array, start: number, end: number): string; - static _base64fromByteArray(u8: Uint8Array): string; - static toBase64(buffer: Uint8Array): string; - static fromBase64(base64: string, length?: number): SerialBuffer; - static toBase64Url(buffer: Uint8Array): string; - static fromBase64Url(base64: string, length?: number): SerialBuffer; - static toBase32(buf: Uint8Array, alphabet?: string): string; - static fromBase32(base32: string, alphabet?: string): Uint8Array; - static toHex(buffer: Uint8Array): string; - static fromHex(hex: string, length?: number): SerialBuffer; - private static _utf8TextEncoder; - static fromUtf8(str: string): Uint8Array; - private static _utf8TextDecoder; - static toUtf8(buf: TypedArray): string; - static fromAny(o: Uint8Array | string, length?: number): SerialBuffer; - static equals(a: TypedArray, b: TypedArray): boolean; - /** - * Returns -1 if a is smaller than b, 1 if a is larger than b, 0 if a equals b. - * Shorter arrays are always considered smaller than longer ones. - */ - static compare(a: TypedArray, b: TypedArray): number; - static xor(a: Uint8Array, b: Uint8Array): Uint8Array; - private static _toUint8View; -} - -declare abstract class Serializable { - /** - * Checks for equality with another Serializable. - */ - equals(o: unknown): boolean; - /** - * Compares this object to another object. - * - * Returns a negative number if `this` is smaller than o, a positive number if `this` is larger than o, and zero if equal. - */ - compare(o: Serializable): number; - abstract serialize(buf?: SerialBuffer): SerialBuffer; - /** - * Formats the object into a hex string. - */ - toString(): string; - /** - * Formats the object into a base64 string. - */ - toBase64(): string; - /** - * Formats the object into a hex string. - */ - toHex(): string; -} - -declare class ExtendedPrivateKey extends Serializable { - static CHAIN_CODE_SIZE: number; - private _key; - private _chainCode; - /** - * Creates an ExtendedPrivateKey from a private key and chain code. - */ - constructor(key: PrivateKey, chainCode: Uint8Array); - /** - * Generates the master ExtendedPrivateKey from a seed. - */ - static generateMasterKey(seed: Uint8Array): ExtendedPrivateKey; - /** - * Derives a child ExtendedPrivateKey from the current key at the provided index. - */ - derive(index: number): ExtendedPrivateKey; - /** - * Tests if a HD derivation path is valid. - */ - static isValidPath(path: string): boolean; - /** - * Derives a child ExtendedPrivateKey from the current key at the provided path. - */ - derivePath(path: string): ExtendedPrivateKey; - /** - * Derives an ExtendedPrivateKey from a seed and a derivation path. - */ - static derivePathFromSeed(path: string, seed: Uint8Array): ExtendedPrivateKey; - /** - * Deserializes an ExtendedPrivateKey from a byte array. - */ - static deserialize(buf: SerialBuffer): ExtendedPrivateKey; - /** - * Deserializes an ExtendedPrivateKey from a hex string. - */ - static fromHex(hex: string): ExtendedPrivateKey; - /** - * Serializes the ExtendedPrivateKey to a byte array. - */ - serialize(buf?: SerialBuffer): SerialBuffer; - /** - * Returns the serialized size of this ExtendedPrivateKey. - */ - get serializedSize(): number; - /** - * Checks for equality with another ExtendedPrivateKey. - */ - equals(o: unknown): boolean; - /** - * Returns the private key of this ExtendedPrivateKey. - */ - get privateKey(): PrivateKey; - /** - * Returns the chain code of this ExtendedPrivateKey. - */ - get chainCode(): Uint8Array; - /** - * Returns the address related to this ExtendedPrivateKey. - */ - toAddress(): Address; -} - -declare abstract class Secret extends Serializable { - private _type; - private _purposeId; - static SIZE: number; - static ENCRYPTION_SALT_SIZE: number; - static ENCRYPTION_KDF_ROUNDS: number; - static ENCRYPTION_CHECKSUM_SIZE: number; - static ENCRYPTION_CHECKSUM_SIZE_V3: number; - constructor(type: Secret.Type, purposeId: number); - /** - * Decrypts a Secret from an encrypted byte array and its password. - */ - static fromEncrypted(buf: SerialBuffer, key: Uint8Array): Promise; - static exportEncrypted(secret: Secret | PrivateKey, key: Uint8Array): Promise; - /** - * Encrypts the Secret with a password. - */ - exportEncrypted(key: Uint8Array): Promise; - /** - * Returns the serialized size of this object when encrypted. - */ - get encryptedSize(): number; - private static _decryptV3; -} -declare namespace Secret { - enum Type { - PRIVATE_KEY = 1, - ENTROPY = 2 - } -} - -declare class Entropy extends Secret { - static SIZE: number; - static PURPOSE_ID: number; - private _obj; - /** - * Creates a new Entropy from a byte array. - */ - constructor(arg: Uint8Array); - /** - * Generates a new Entropy object from secure randomness. - */ - static generate(): Entropy; - /** - * Derives an ExtendedPrivateKey from the Entropy. - */ - toExtendedPrivateKey(password?: string, wordlist?: string[]): ExtendedPrivateKey; - /** - * Converts the Entropy into a mnemonic. - */ - toMnemonic(wordlist?: string[]): string[]; - /** - * Deserializes an Entropy object from a byte array. - */ - static deserialize(buf: SerialBuffer): Entropy; - /** - * Deserializes an Entropy object from a hex string. - */ - static fromHex(hex: string): Entropy; - /** - * Serializes the Entropy to a byte array. - */ - serialize(buf?: SerialBuffer): SerialBuffer; - /** - * Returns the serialized size of this Entropy. - */ - get serializedSize(): number; - /** - * Overwrites this Entropy's bytes with a replacement in-memory - */ - overwrite(entropy: Entropy): void; - /** - * Checks for equality with another Entropy. - */ - equals(o: unknown): boolean; -} - -declare class MnemonicUtils { - /** - * The English wordlist. - */ - static ENGLISH_WORDLIST: string[]; - /** - * The default English wordlist. - */ - static DEFAULT_WORDLIST: string[]; - /** - * Converts an Entropy to a mnemonic. - */ - static entropyToMnemonic(entropy: string | ArrayBuffer | Uint8Array | Entropy, wordlist?: string[]): string[]; - /** - * Converts a mnemonic to an Entropy. - */ - static mnemonicToEntropy(mnemonic: string[] | string, wordlist?: string[]): Entropy; - /** - * Converts a mnemonic to a seed. - * - * Optionally takes a password to use for the seed derivation. - */ - static mnemonicToSeed(mnemonic: string[] | string, password?: string): SerialBuffer; - /** - * Converts a mnemonic to an extended private key. - * - * Optionally takes a password to use for the seed derivation. - */ - static mnemonicToExtendedPrivateKey(mnemonic: string[] | string, password?: string): ExtendedPrivateKey; - /** - * Tests if a mnemonic can be both for a legacy Nimiq wallet and a BIP39 wallet. - */ - static isCollidingChecksum(entropy: Entropy): boolean; - /** - * Gets the type of a mnemonic. - * - * Return values: - * - `0 = MnemonicType.LEGACY`: the mnemonic is for a legacy Nimiq wallet. - * - `1 = MnemonicType.BIP39`: the mnemonic is for a BIP39 wallet. - * - `-1 = MnemonicType.UNKNOWN`: the mnemonic can be for both. - * - * Throws if the menmonic is invalid. - */ - static getMnemonicType(mnemonic: string[] | string, wordlist?: string[]): MnemonicUtils.MnemonicType; - private static _crcChecksum; - private static _sha256Checksum; - private static _entropyToBits; - private static _normalizeEntropy; - private static _bitsToMnemonic; - private static _mnemonicToBits; - private static _bitsToEntropy; - private static _salt; - private static _fromBinary; - private static _toBinary; -} -declare namespace MnemonicUtils { - enum MnemonicType { - UNKNOWN = -1, - LEGACY = 0, - BIP39 = 1 - } -} - -declare class NumberUtils { - static UINT8_MAX: number; - static UINT16_MAX: number; - static UINT32_MAX: number; - static UINT64_MAX: number; - static isInteger(val: unknown): val is number; - static isUint8(val: unknown): boolean; - static isUint16(val: unknown): boolean; - static isUint32(val: unknown): boolean; - static isUint64(val: unknown): boolean; -} - -declare class StringUtils { - static isWellFormed(str: string): boolean; - static isHex(str: string): boolean; - static isHexBytes(str: string, length?: number): boolean; - /** - * Copied from: - * https://github.com/ljharb/es-abstract/blob/main/2024/IsStringWellFormedUnicode.js - */ - private static _isWellFormedUnicode; - /** - * Copied from: - * https://github.com/ljharb/es-abstract/blob/main/2024/CodePointAt.js - */ - private static _codePointAt; - /** - * Copied from: - * https://github.com/ljharb/es-abstract/blob/main/helpers/isLeadingSurrogate.js - */ - private static _isLeadingSurrogate; - /** - * Copied from: - * https://github.com/ljharb/es-abstract/blob/main/helpers/isTrailingSurrogate.js - */ - private static _isTrailingSurrogate; - /** - * Copied from: - * https://github.com/ljharb/es-abstract/blob/main/2024/UTF16SurrogatePairToCodePoint.js - */ - private static _utf16SurrogatePairToCodePoint; -} - -export { ArrayUtils, BufferUtils, Entropy, ExtendedPrivateKey, MnemonicUtils, NumberUtils, Secret, SerialBuffer, StringUtils }; diff --git a/public/index.html b/public/index.html index ff40df49f..356696a73 100644 --- a/public/index.html +++ b/public/index.html @@ -24,14 +24,12 @@ /** @type {Promise | undefined} */ let initPromise; - if (sessionStorage.getItem('debug')) { - window.loadAlbatross = async function() { - return initPromise || (initPromise = new Promise(async resolve => { - await init(); - resolve(Nimiq); - })); - } - } + window.loadAlbatross = async function() { + return initPromise || (initPromise = new Promise(async resolve => { + await init(); + resolve(Nimiq); + })); + }; diff --git a/src/components/staking/StakingGraphPage.vue b/src/components/staking/StakingGraphPage.vue index 63e8dcf98..c679ce30b 100644 --- a/src/components/staking/StakingGraphPage.vue +++ b/src/components/staking/StakingGraphPage.vue @@ -128,9 +128,7 @@ export default defineComponent({ ? activeValidator.value.name : activeValidator.value!.address; - const { Address, TransactionBuilder } = sessionStorage.getItem('debug') - ? await window.loadAlbatross() - : await import('@nimiq/core'); + const { Address, TransactionBuilder } = await window.loadAlbatross(); const client = await getNetworkClient(); try { diff --git a/src/components/staking/StakingInfoPage.vue b/src/components/staking/StakingInfoPage.vue index 6591605c0..8ee94b8a4 100644 --- a/src/components/staking/StakingInfoPage.vue +++ b/src/components/staking/StakingInfoPage.vue @@ -266,9 +266,7 @@ export default defineComponent({ }); try { - const { Address, TransactionBuilder } = sessionStorage.getItem('debug') - ? await window.loadAlbatross() - : await import('@nimiq/core'); + const { Address, TransactionBuilder } = await window.loadAlbatross(); const client = await getNetworkClient(); const transaction = TransactionBuilder.newSetActiveStake( @@ -338,9 +336,7 @@ export default defineComponent({ }); try { - const { Address, TransactionBuilder } = sessionStorage.getItem('debug') - ? await window.loadAlbatross() - : await import('@nimiq/core'); + const { Address, TransactionBuilder } = await window.loadAlbatross(); const client = await getNetworkClient(); const transactions = [ diff --git a/src/components/staking/ValidatorDetailsOverlay.vue b/src/components/staking/ValidatorDetailsOverlay.vue index 584e392db..1fe43cc01 100644 --- a/src/components/staking/ValidatorDetailsOverlay.vue +++ b/src/components/staking/ValidatorDetailsOverlay.vue @@ -113,9 +113,7 @@ export default defineComponent({ title: context.root.$t('Changing validator') as string, }); - const { Address, TransactionBuilder } = sessionStorage.getItem('debug') - ? await window.loadAlbatross() - : await import('@nimiq/core'); + const { Address, TransactionBuilder } = await window.loadAlbatross(); const client = await getNetworkClient(); const transaction = TransactionBuilder.newUpdateStaker( diff --git a/src/network.ts b/src/network.ts index b994caa2c..0bf8515b0 100644 --- a/src/network.ts +++ b/src/network.ts @@ -26,9 +26,7 @@ export async function getNetworkClient() { clientPromise = clientPromise || (async () => { // Note: we don't need to reset clientPromise on changes to the config because we only use config.environment // which never changes at runtime. Changing config.nimiqSeeds at runtime is not supported. - const { ClientConfiguration, Client } = sessionStorage.getItem('debug') - ? await window.loadAlbatross() - : await import('@nimiq/core'); + const { ClientConfiguration, Client } = await window.loadAlbatross(); const clientConfig = new ClientConfiguration(); clientConfig.network(config.environment === ENV_MAIN ? 'mainalbatross' : 'testalbatross'); clientConfig.seedNodes(config.nimiqSeeds);