@ledgerhq/coin-aptos 2.5.1 → 2.5.2-nightly.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.unimportedrc.json +5 -8
- package/CHANGELOG.md +8 -0
- package/lib/__tests__/bridge/deviceTransactionConfig.test.js +115 -30
- package/lib/__tests__/bridge/deviceTransactionConfig.test.js.map +1 -1
- package/lib/__tests__/bridge/getFeesForTransaction.test.js +10 -10
- package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
- package/lib/__tests__/bridge/getTransactionStatus.test.js +193 -2
- package/lib/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
- package/lib/__tests__/bridge/index.test.js +4 -1
- package/lib/__tests__/bridge/index.test.js.map +1 -1
- package/lib/__tests__/bridge/logic.test.js +9 -9
- package/lib/__tests__/bridge/logic.test.js.map +1 -1
- package/lib/__tests__/bridge/prepareTransaction.test.js +1 -0
- package/lib/__tests__/bridge/prepareTransaction.test.js.map +1 -1
- package/lib/__tests__/bridge/serialization.d.ts +2 -0
- package/lib/__tests__/bridge/serialization.d.ts.map +1 -0
- package/lib/__tests__/bridge/serialization.js +91 -0
- package/lib/__tests__/bridge/serialization.js.map +1 -0
- package/lib/__tests__/bridge/synchronisation.test.js +763 -23
- package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
- package/lib/__tests__/logic/staking.test.d.ts +2 -0
- package/lib/__tests__/logic/staking.test.d.ts.map +1 -0
- package/lib/__tests__/logic/staking.test.js +202 -0
- package/lib/__tests__/logic/staking.test.js.map +1 -0
- package/lib/__tests__/network/client.test.js +3 -3
- package/lib/__tests__/network/validators.test.d.ts +2 -0
- package/lib/__tests__/network/validators.test.d.ts.map +1 -0
- package/lib/__tests__/network/validators.test.js +98 -0
- package/lib/__tests__/network/validators.test.js.map +1 -0
- package/lib/__tests__/utils/IconGenerator.test.d.ts +2 -0
- package/lib/__tests__/utils/IconGenerator.test.d.ts.map +1 -0
- package/lib/__tests__/utils/IconGenerator.test.js +14 -0
- package/lib/__tests__/utils/IconGenerator.test.js.map +1 -0
- package/lib/__tests__/utils/index.test.d.ts +2 -0
- package/lib/__tests__/utils/index.test.d.ts.map +1 -0
- package/lib/__tests__/utils/index.test.js +11 -0
- package/lib/__tests__/utils/index.test.js.map +1 -0
- package/lib/bridge/bridge.fixture.d.ts.map +1 -1
- package/lib/bridge/bridge.fixture.js +12 -0
- package/lib/bridge/bridge.fixture.js.map +1 -1
- package/lib/bridge/deviceTransactionConfig.d.ts +7 -8
- package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -1
- package/lib/bridge/deviceTransactionConfig.js +83 -16
- package/lib/bridge/deviceTransactionConfig.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.d.ts +4 -4
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +1 -1
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
- package/lib/bridge/getFeesForTransaction.js +8 -4
- package/lib/bridge/getFeesForTransaction.js.map +1 -1
- package/lib/bridge/getTransactionStatus.d.ts +2 -3
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/getTransactionStatus.js +139 -25
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/index.d.ts +3 -3
- package/lib/bridge/index.d.ts.map +1 -1
- package/lib/bridge/index.js +9 -2
- package/lib/bridge/index.js.map +1 -1
- package/lib/bridge/logic.d.ts +3 -3
- package/lib/bridge/logic.d.ts.map +1 -1
- package/lib/bridge/logic.js +23 -9
- package/lib/bridge/logic.js.map +1 -1
- package/lib/bridge/prepareTransaction.d.ts +2 -3
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +46 -10
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/serialization.d.ts +7 -0
- package/lib/bridge/serialization.d.ts.map +1 -0
- package/lib/bridge/serialization.js +51 -0
- package/lib/bridge/serialization.js.map +1 -0
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +17 -5
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/synchronisation.d.ts +6 -4
- package/lib/bridge/synchronisation.d.ts.map +1 -1
- package/lib/bridge/synchronisation.js +51 -4
- package/lib/bridge/synchronisation.js.map +1 -1
- package/lib/constants.d.ts +25 -1
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +54 -8
- package/lib/constants.js.map +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -15
- package/lib/index.js.map +1 -1
- package/lib/logic/buildTransaction.d.ts.map +1 -1
- package/lib/logic/buildTransaction.js +42 -19
- package/lib/logic/buildTransaction.js.map +1 -1
- package/lib/logic/getCoinAndAmounts.d.ts +2 -0
- package/lib/logic/getCoinAndAmounts.d.ts.map +1 -1
- package/lib/logic/getCoinAndAmounts.js +65 -38
- package/lib/logic/getCoinAndAmounts.js.map +1 -1
- package/lib/logic/staking.d.ts +12 -0
- package/lib/logic/staking.d.ts.map +1 -0
- package/lib/logic/staking.js +81 -0
- package/lib/logic/staking.js.map +1 -0
- package/lib/logic/transactionsToOperations.js +3 -3
- package/lib/logic/transactionsToOperations.js.map +1 -1
- package/lib/network/client.d.ts +4 -1
- package/lib/network/client.d.ts.map +1 -1
- package/lib/network/client.js +32 -1
- package/lib/network/client.js.map +1 -1
- package/lib/network/graphql/queries.d.ts +2 -0
- package/lib/network/graphql/queries.d.ts.map +1 -1
- package/lib/network/graphql/queries.js +42 -2
- package/lib/network/graphql/queries.js.map +1 -1
- package/lib/network/graphql/types.d.ts +57 -6
- package/lib/network/graphql/types.d.ts.map +1 -1
- package/lib/network/index.d.ts.map +1 -1
- package/lib/network/index.js.map +1 -1
- package/lib/network/validators.d.ts +3 -0
- package/lib/network/validators.d.ts.map +1 -0
- package/lib/network/validators.js +42 -0
- package/lib/network/validators.js.map +1 -0
- package/lib/preload-data.d.ts +7 -0
- package/lib/preload-data.d.ts.map +1 -0
- package/lib/preload-data.js +42 -0
- package/lib/preload-data.js.map +1 -0
- package/lib/preload.d.ts +6 -0
- package/lib/preload.d.ts.map +1 -0
- package/lib/preload.js +21 -0
- package/lib/preload.js.map +1 -0
- package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib/test/bridgeDatasetTest.js +1 -0
- package/lib/test/bridgeDatasetTest.js.map +1 -1
- package/lib/types/index.d.ts +92 -8
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js.map +1 -1
- package/lib/utils/IconGenerator.d.ts +12 -0
- package/lib/utils/IconGenerator.d.ts.map +1 -0
- package/lib/utils/IconGenerator.js +138 -0
- package/lib/utils/IconGenerator.js.map +1 -0
- package/lib/utils/index.d.ts +3 -0
- package/lib/utils/index.d.ts.map +1 -0
- package/lib/utils/index.js +31 -0
- package/lib/utils/index.js.map +1 -0
- package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js +113 -8
- package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js.map +1 -1
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +10 -10
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
- package/lib-es/__tests__/bridge/getTransactionStatus.test.js +194 -3
- package/lib-es/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
- package/lib-es/__tests__/bridge/index.test.js +4 -1
- package/lib-es/__tests__/bridge/index.test.js.map +1 -1
- package/lib-es/__tests__/bridge/logic.test.js +10 -10
- package/lib-es/__tests__/bridge/logic.test.js.map +1 -1
- package/lib-es/__tests__/bridge/prepareTransaction.test.js +1 -0
- package/lib-es/__tests__/bridge/prepareTransaction.test.js.map +1 -1
- package/lib-es/__tests__/bridge/serialization.d.ts +2 -0
- package/lib-es/__tests__/bridge/serialization.d.ts.map +1 -0
- package/lib-es/__tests__/bridge/serialization.js +86 -0
- package/lib-es/__tests__/bridge/serialization.js.map +1 -0
- package/lib-es/__tests__/bridge/synchronisation.test.js +763 -23
- package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -1
- package/lib-es/__tests__/logic/staking.test.d.ts +2 -0
- package/lib-es/__tests__/logic/staking.test.d.ts.map +1 -0
- package/lib-es/__tests__/logic/staking.test.js +197 -0
- package/lib-es/__tests__/logic/staking.test.js.map +1 -0
- package/lib-es/__tests__/network/client.test.js +3 -3
- package/lib-es/__tests__/network/validators.test.d.ts +2 -0
- package/lib-es/__tests__/network/validators.test.d.ts.map +1 -0
- package/lib-es/__tests__/network/validators.test.js +93 -0
- package/lib-es/__tests__/network/validators.test.js.map +1 -0
- package/lib-es/__tests__/utils/IconGenerator.test.d.ts +2 -0
- package/lib-es/__tests__/utils/IconGenerator.test.d.ts.map +1 -0
- package/lib-es/__tests__/utils/IconGenerator.test.js +12 -0
- package/lib-es/__tests__/utils/IconGenerator.test.js.map +1 -0
- package/lib-es/__tests__/utils/index.test.d.ts +2 -0
- package/lib-es/__tests__/utils/index.test.d.ts.map +1 -0
- package/lib-es/__tests__/utils/index.test.js +9 -0
- package/lib-es/__tests__/utils/index.test.js.map +1 -0
- package/lib-es/bridge/bridge.fixture.d.ts.map +1 -1
- package/lib-es/bridge/bridge.fixture.js +12 -0
- package/lib-es/bridge/bridge.fixture.js.map +1 -1
- package/lib-es/bridge/deviceTransactionConfig.d.ts +7 -8
- package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -1
- package/lib-es/bridge/deviceTransactionConfig.js +83 -14
- package/lib-es/bridge/deviceTransactionConfig.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts +4 -4
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
- package/lib-es/bridge/getFeesForTransaction.js +9 -5
- package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
- package/lib-es/bridge/getTransactionStatus.d.ts +2 -3
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +140 -26
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/index.d.ts +3 -3
- package/lib-es/bridge/index.d.ts.map +1 -1
- package/lib-es/bridge/index.js +9 -2
- package/lib-es/bridge/index.js.map +1 -1
- package/lib-es/bridge/logic.d.ts +3 -3
- package/lib-es/bridge/logic.d.ts.map +1 -1
- package/lib-es/bridge/logic.js +23 -9
- package/lib-es/bridge/logic.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.d.ts +2 -3
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +46 -10
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/serialization.d.ts +7 -0
- package/lib-es/bridge/serialization.d.ts.map +1 -0
- package/lib-es/bridge/serialization.js +41 -0
- package/lib-es/bridge/serialization.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -1
- package/lib-es/bridge/signOperation.js +17 -5
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/synchronisation.d.ts +6 -4
- package/lib-es/bridge/synchronisation.d.ts.map +1 -1
- package/lib-es/bridge/synchronisation.js +49 -3
- package/lib-es/bridge/synchronisation.js.map +1 -1
- package/lib-es/constants.d.ts +25 -1
- package/lib-es/constants.d.ts.map +1 -1
- package/lib-es/constants.js +53 -7
- package/lib-es/constants.js.map +1 -1
- package/lib-es/index.d.ts +0 -1
- package/lib-es/index.d.ts.map +1 -1
- package/lib-es/index.js +0 -1
- package/lib-es/index.js.map +1 -1
- package/lib-es/logic/buildTransaction.d.ts.map +1 -1
- package/lib-es/logic/buildTransaction.js +42 -19
- package/lib-es/logic/buildTransaction.js.map +1 -1
- package/lib-es/logic/getCoinAndAmounts.d.ts +2 -0
- package/lib-es/logic/getCoinAndAmounts.d.ts.map +1 -1
- package/lib-es/logic/getCoinAndAmounts.js +66 -39
- package/lib-es/logic/getCoinAndAmounts.js.map +1 -1
- package/lib-es/logic/staking.d.ts +12 -0
- package/lib-es/logic/staking.d.ts.map +1 -0
- package/lib-es/logic/staking.js +67 -0
- package/lib-es/logic/staking.js.map +1 -0
- package/lib-es/logic/transactionsToOperations.js +4 -4
- package/lib-es/logic/transactionsToOperations.js.map +1 -1
- package/lib-es/network/client.d.ts +4 -1
- package/lib-es/network/client.d.ts.map +1 -1
- package/lib-es/network/client.js +32 -1
- package/lib-es/network/client.js.map +1 -1
- package/lib-es/network/graphql/queries.d.ts +2 -0
- package/lib-es/network/graphql/queries.d.ts.map +1 -1
- package/lib-es/network/graphql/queries.js +41 -1
- package/lib-es/network/graphql/queries.js.map +1 -1
- package/lib-es/network/graphql/types.d.ts +57 -6
- package/lib-es/network/graphql/types.d.ts.map +1 -1
- package/lib-es/network/index.d.ts.map +1 -1
- package/lib-es/network/index.js.map +1 -1
- package/lib-es/network/validators.d.ts +3 -0
- package/lib-es/network/validators.d.ts.map +1 -0
- package/lib-es/network/validators.js +35 -0
- package/lib-es/network/validators.js.map +1 -0
- package/lib-es/preload-data.d.ts +7 -0
- package/lib-es/preload-data.d.ts.map +1 -0
- package/lib-es/preload-data.js +36 -0
- package/lib-es/preload-data.js.map +1 -0
- package/lib-es/preload.d.ts +6 -0
- package/lib-es/preload.d.ts.map +1 -0
- package/lib-es/preload.js +16 -0
- package/lib-es/preload.js.map +1 -0
- package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib-es/test/bridgeDatasetTest.js +1 -0
- package/lib-es/test/bridgeDatasetTest.js.map +1 -1
- package/lib-es/types/index.d.ts +92 -8
- package/lib-es/types/index.d.ts.map +1 -1
- package/lib-es/types/index.js.map +1 -1
- package/lib-es/utils/IconGenerator.d.ts +12 -0
- package/lib-es/utils/IconGenerator.d.ts.map +1 -0
- package/lib-es/utils/IconGenerator.js +134 -0
- package/lib-es/utils/IconGenerator.js.map +1 -0
- package/lib-es/utils/index.d.ts +3 -0
- package/lib-es/utils/index.d.ts.map +1 -0
- package/lib-es/utils/index.js +13 -0
- package/lib-es/utils/index.js.map +1 -0
- package/package.json +12 -7
- package/src/__tests__/bridge/deviceTransactionConfig.test.ts +120 -8
- package/src/__tests__/bridge/getFeesForTransaction.test.ts +10 -10
- package/src/__tests__/bridge/getTransactionStatus.test.ts +247 -3
- package/src/__tests__/bridge/index.test.ts +5 -1
- package/src/__tests__/bridge/logic.test.ts +10 -10
- package/src/__tests__/bridge/prepareTransaction.test.ts +4 -4
- package/src/__tests__/bridge/serialization.ts +103 -0
- package/src/__tests__/bridge/synchronisation.test.ts +798 -32
- package/src/__tests__/logic/staking.test.ts +221 -0
- package/src/__tests__/network/client.test.ts +3 -3
- package/src/__tests__/network/validators.test.ts +105 -0
- package/src/__tests__/utils/IconGenerator.test.ts +13 -0
- package/src/__tests__/utils/index.test.ts +11 -0
- package/src/bridge/bridge.fixture.ts +12 -0
- package/src/bridge/deviceTransactionConfig.ts +90 -21
- package/src/bridge/estimateMaxSpendable.ts +5 -5
- package/src/bridge/getFeesForTransaction.ts +17 -5
- package/src/bridge/getTransactionStatus.ts +208 -32
- package/src/bridge/index.ts +14 -5
- package/src/bridge/logic.ts +28 -12
- package/src/bridge/prepareTransaction.ts +72 -24
- package/src/bridge/serialization.ts +52 -0
- package/src/bridge/signOperation.ts +20 -7
- package/src/bridge/synchronisation.ts +69 -12
- package/src/constants.ts +64 -2
- package/src/index.ts +0 -2
- package/src/logic/buildTransaction.ts +49 -24
- package/src/logic/getCoinAndAmounts.ts +91 -41
- package/src/logic/staking.ts +105 -0
- package/src/logic/transactionsToOperations.ts +5 -5
- package/src/network/client.ts +44 -4
- package/src/network/graphql/queries.ts +46 -1
- package/src/network/graphql/types.ts +63 -6
- package/src/network/index.ts +1 -0
- package/src/network/validators.ts +48 -0
- package/src/preload-data.ts +43 -0
- package/src/preload.ts +23 -0
- package/src/test/bridgeDatasetTest.ts +1 -0
- package/src/types/index.ts +106 -8
- package/src/utils/IconGenerator.ts +166 -0
- package/src/utils/index.ts +16 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// Utility for Xorshift-based PRNG
|
|
2
|
+
// Random number generator using Xorshift algorithm, as established in the Ethereum Blockies
|
|
3
|
+
// https://github.com/ethereum/blockies
|
|
4
|
+
class XorshiftPRNG {
|
|
5
|
+
private state: number[] = [0, 0, 0, 0];
|
|
6
|
+
|
|
7
|
+
seed(seedStr: string): void {
|
|
8
|
+
this.state.fill(0);
|
|
9
|
+
for (let i = 0; i < seedStr.length; i++) {
|
|
10
|
+
this.state[i % 4] = (this.state[i % 4] << 5) - this.state[i % 4] + seedStr.charCodeAt(i);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
random(): number {
|
|
15
|
+
const t = this.state[0] ^ (this.state[0] << 11);
|
|
16
|
+
this.state[0] = this.state[1];
|
|
17
|
+
this.state[1] = this.state[2];
|
|
18
|
+
this.state[2] = this.state[3];
|
|
19
|
+
this.state[3] = this.state[3] ^ (this.state[3] >> 19) ^ t ^ (t >> 8);
|
|
20
|
+
return (this.state[3] >>> 0) / ((1 << 31) >>> 0);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type RGB = [number, number, number];
|
|
25
|
+
|
|
26
|
+
// Identicon generator class
|
|
27
|
+
// Generates a unique identicon based on a seed string, and returns it as a BMP image data URL.
|
|
28
|
+
export class IconGenerator {
|
|
29
|
+
private rng: XorshiftPRNG;
|
|
30
|
+
|
|
31
|
+
constructor(seed: string) {
|
|
32
|
+
this.rng = new XorshiftPRNG();
|
|
33
|
+
this.rng.seed(seed);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private random = () => this.rng.random();
|
|
37
|
+
|
|
38
|
+
// Generates a random color in RGB format
|
|
39
|
+
// The color is generated using HSL values, ensuring a good distribution of colors.
|
|
40
|
+
// The hue is randomized, saturation is between 40% and 100%, and lightness is a combination of random values.
|
|
41
|
+
// The resulting RGB values are rounded to integers between 0 and 255.
|
|
42
|
+
private createColor(): RGB {
|
|
43
|
+
let h = Math.floor(this.random() * 360);
|
|
44
|
+
let s = this.random() * 60 + 40;
|
|
45
|
+
let l = (this.random() + this.random() + this.random() + this.random()) * 25;
|
|
46
|
+
|
|
47
|
+
h = ((h % 360) + 360) % 360;
|
|
48
|
+
s /= 100;
|
|
49
|
+
l /= 100;
|
|
50
|
+
|
|
51
|
+
const hueToRgb = (p: number, q: number, t: number): number => {
|
|
52
|
+
if (t < 0) t += 1;
|
|
53
|
+
if (t > 1) t -= 1;
|
|
54
|
+
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
|
55
|
+
if (t < 1 / 2) return q;
|
|
56
|
+
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
57
|
+
return p;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
if (s === 0) return [l, l, l].map(v => Math.round(v * 255)) as RGB;
|
|
61
|
+
|
|
62
|
+
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
63
|
+
const p = 2 * l - q;
|
|
64
|
+
const r = hueToRgb(p, q, h / 360 + 1 / 3);
|
|
65
|
+
const g = hueToRgb(p, q, h / 360);
|
|
66
|
+
const b = hueToRgb(p, q, h / 360 - 1 / 3);
|
|
67
|
+
|
|
68
|
+
return [r, g, b].map(v => Math.round(v * 255)) as RGB;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Creates a symmetric image data array for the identicon
|
|
72
|
+
// The image is symmetric, with the left half being a mirror of the right half.
|
|
73
|
+
// The data is generated by filling the left half with random values (0, 1, or 2),
|
|
74
|
+
// and mirroring it to the right half.
|
|
75
|
+
private createImageData(size: number): number[] {
|
|
76
|
+
const width = size;
|
|
77
|
+
const dataWidth = Math.ceil(width / 2);
|
|
78
|
+
const mirrorWidth = width - dataWidth;
|
|
79
|
+
const data: number[] = [];
|
|
80
|
+
|
|
81
|
+
for (let y = 0; y < size; y++) {
|
|
82
|
+
const row: number[] = Array.from({ length: dataWidth }, () =>
|
|
83
|
+
Math.floor(this.random() * 2.3),
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const mirrored = row.slice(0, mirrorWidth).reverse();
|
|
87
|
+
row.push(...mirrored);
|
|
88
|
+
|
|
89
|
+
data.push(...row);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return data;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Converts the image data into pixel data for BMP format
|
|
96
|
+
// The pixel data is generated by scaling the image data according to the specified scale factor.
|
|
97
|
+
// Each cell in the image data is represented by a block of pixels in the output,
|
|
98
|
+
// with the color determined by the value in the cell (0 for background, 1 for main color, 2 for spot color).
|
|
99
|
+
private toPixels(
|
|
100
|
+
size: number,
|
|
101
|
+
cellData: number[],
|
|
102
|
+
scale: number,
|
|
103
|
+
color: RGB,
|
|
104
|
+
spotColor: RGB,
|
|
105
|
+
bgColor: RGB,
|
|
106
|
+
): number[] {
|
|
107
|
+
const rowSize = size * scale;
|
|
108
|
+
const rowDataSize = rowSize * 3;
|
|
109
|
+
const data = new Array<number>(rowSize * rowDataSize);
|
|
110
|
+
|
|
111
|
+
for (let x = 0; x < size; x++) {
|
|
112
|
+
for (let y = 0; y < size; y++) {
|
|
113
|
+
const value = cellData[(size - x - 1) * size + y];
|
|
114
|
+
const c = value === 0 ? bgColor : value === 1 ? color : spotColor;
|
|
115
|
+
|
|
116
|
+
for (let dx = 0; dx < scale; dx++) {
|
|
117
|
+
for (let dy = 0; dy < scale; dy++) {
|
|
118
|
+
const pixelIndex = (x * scale + dx) * rowDataSize + (y * scale + dy) * 3;
|
|
119
|
+
[2, 1, 0].forEach((offset, idx) => {
|
|
120
|
+
data[pixelIndex + offset] = c[idx];
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return data;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Converts a number to little-endian hexadecimal format
|
|
131
|
+
private static toLEHex(n: number): string {
|
|
132
|
+
return (n + 2 ** 32).toString(16).match(/\B../g)?.reverse().join("") ?? "";
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Generates a BMP image data URL from pixel data
|
|
136
|
+
// The BMP format is constructed with a header and pixel data correctly padded.
|
|
137
|
+
// The header includes metadata such as size, width, height, and color depth.
|
|
138
|
+
private static generateBMP(width: number, pixels: number[]): string {
|
|
139
|
+
const height = Math.floor(pixels.length / (width * 3));
|
|
140
|
+
const size = this.toLEHex(26 + pixels.length);
|
|
141
|
+
const wh = this.toLEHex(width).slice(0, 4) + this.toLEHex(height).slice(0, 4);
|
|
142
|
+
const headerHex = `424d${size}000000001b0000000C000000${wh}0100180000`;
|
|
143
|
+
|
|
144
|
+
const headerBytes = headerHex.match(/../g)?.map(h => parseInt(h, 16)) ?? [];
|
|
145
|
+
const pixelChars = pixels.map(p => String.fromCharCode(p));
|
|
146
|
+
|
|
147
|
+
const base64Header = btoa(String.fromCharCode(...headerBytes));
|
|
148
|
+
const base64Pixels = btoa(pixelChars.join(""));
|
|
149
|
+
|
|
150
|
+
return `data:image/bmp;base64,${base64Header}${base64Pixels}`;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Generates a BMP image data URL for the identicon
|
|
154
|
+
// The size and scale can be adjusted, with a default size of 8 and scale of 4.
|
|
155
|
+
// The generated image will have a symmetric pattern based on the seed string.
|
|
156
|
+
generate(size = 8, scale = 4): string {
|
|
157
|
+
const mainColor = this.createColor();
|
|
158
|
+
const backgroundColor = this.createColor();
|
|
159
|
+
const spotColor = this.createColor();
|
|
160
|
+
|
|
161
|
+
const cellData = this.createImageData(size);
|
|
162
|
+
const pixelData = this.toPixels(size, cellData, scale, mainColor, spotColor, backgroundColor);
|
|
163
|
+
|
|
164
|
+
return IconGenerator.generateBMP(size * scale, pixelData);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getEnv } from "@ledgerhq/live-env";
|
|
2
|
+
|
|
3
|
+
export * from "./IconGenerator";
|
|
4
|
+
|
|
5
|
+
export function endpointByCurrencyId(currencyId: string): string {
|
|
6
|
+
const endpoints: Record<string, string> = {
|
|
7
|
+
aptos: getEnv("APTOS_API_ENDPOINT"),
|
|
8
|
+
aptos_testnet: getEnv("APTOS_TESTNET_API_ENDPOINT"),
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
if (currencyId in endpoints) {
|
|
12
|
+
return endpoints[currencyId];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
throw Error(`unexpected currency id format <${currencyId}>, should be like aptos[_testnet]`);
|
|
16
|
+
}
|