@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,134 @@
|
|
|
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
|
+
state = [0, 0, 0, 0];
|
|
6
|
+
seed(seedStr) {
|
|
7
|
+
this.state.fill(0);
|
|
8
|
+
for (let i = 0; i < seedStr.length; i++) {
|
|
9
|
+
this.state[i % 4] = (this.state[i % 4] << 5) - this.state[i % 4] + seedStr.charCodeAt(i);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
random() {
|
|
13
|
+
const t = this.state[0] ^ (this.state[0] << 11);
|
|
14
|
+
this.state[0] = this.state[1];
|
|
15
|
+
this.state[1] = this.state[2];
|
|
16
|
+
this.state[2] = this.state[3];
|
|
17
|
+
this.state[3] = this.state[3] ^ (this.state[3] >> 19) ^ t ^ (t >> 8);
|
|
18
|
+
return (this.state[3] >>> 0) / ((1 << 31) >>> 0);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
// Identicon generator class
|
|
22
|
+
// Generates a unique identicon based on a seed string, and returns it as a BMP image data URL.
|
|
23
|
+
export class IconGenerator {
|
|
24
|
+
rng;
|
|
25
|
+
constructor(seed) {
|
|
26
|
+
this.rng = new XorshiftPRNG();
|
|
27
|
+
this.rng.seed(seed);
|
|
28
|
+
}
|
|
29
|
+
random = () => this.rng.random();
|
|
30
|
+
// Generates a random color in RGB format
|
|
31
|
+
// The color is generated using HSL values, ensuring a good distribution of colors.
|
|
32
|
+
// The hue is randomized, saturation is between 40% and 100%, and lightness is a combination of random values.
|
|
33
|
+
// The resulting RGB values are rounded to integers between 0 and 255.
|
|
34
|
+
createColor() {
|
|
35
|
+
let h = Math.floor(this.random() * 360);
|
|
36
|
+
let s = this.random() * 60 + 40;
|
|
37
|
+
let l = (this.random() + this.random() + this.random() + this.random()) * 25;
|
|
38
|
+
h = ((h % 360) + 360) % 360;
|
|
39
|
+
s /= 100;
|
|
40
|
+
l /= 100;
|
|
41
|
+
const hueToRgb = (p, q, t) => {
|
|
42
|
+
if (t < 0)
|
|
43
|
+
t += 1;
|
|
44
|
+
if (t > 1)
|
|
45
|
+
t -= 1;
|
|
46
|
+
if (t < 1 / 6)
|
|
47
|
+
return p + (q - p) * 6 * t;
|
|
48
|
+
if (t < 1 / 2)
|
|
49
|
+
return q;
|
|
50
|
+
if (t < 2 / 3)
|
|
51
|
+
return p + (q - p) * (2 / 3 - t) * 6;
|
|
52
|
+
return p;
|
|
53
|
+
};
|
|
54
|
+
if (s === 0)
|
|
55
|
+
return [l, l, l].map(v => Math.round(v * 255));
|
|
56
|
+
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
57
|
+
const p = 2 * l - q;
|
|
58
|
+
const r = hueToRgb(p, q, h / 360 + 1 / 3);
|
|
59
|
+
const g = hueToRgb(p, q, h / 360);
|
|
60
|
+
const b = hueToRgb(p, q, h / 360 - 1 / 3);
|
|
61
|
+
return [r, g, b].map(v => Math.round(v * 255));
|
|
62
|
+
}
|
|
63
|
+
// Creates a symmetric image data array for the identicon
|
|
64
|
+
// The image is symmetric, with the left half being a mirror of the right half.
|
|
65
|
+
// The data is generated by filling the left half with random values (0, 1, or 2),
|
|
66
|
+
// and mirroring it to the right half.
|
|
67
|
+
createImageData(size) {
|
|
68
|
+
const width = size;
|
|
69
|
+
const dataWidth = Math.ceil(width / 2);
|
|
70
|
+
const mirrorWidth = width - dataWidth;
|
|
71
|
+
const data = [];
|
|
72
|
+
for (let y = 0; y < size; y++) {
|
|
73
|
+
const row = Array.from({ length: dataWidth }, () => Math.floor(this.random() * 2.3));
|
|
74
|
+
const mirrored = row.slice(0, mirrorWidth).reverse();
|
|
75
|
+
row.push(...mirrored);
|
|
76
|
+
data.push(...row);
|
|
77
|
+
}
|
|
78
|
+
return data;
|
|
79
|
+
}
|
|
80
|
+
// Converts the image data into pixel data for BMP format
|
|
81
|
+
// The pixel data is generated by scaling the image data according to the specified scale factor.
|
|
82
|
+
// Each cell in the image data is represented by a block of pixels in the output,
|
|
83
|
+
// with the color determined by the value in the cell (0 for background, 1 for main color, 2 for spot color).
|
|
84
|
+
toPixels(size, cellData, scale, color, spotColor, bgColor) {
|
|
85
|
+
const rowSize = size * scale;
|
|
86
|
+
const rowDataSize = rowSize * 3;
|
|
87
|
+
const data = new Array(rowSize * rowDataSize);
|
|
88
|
+
for (let x = 0; x < size; x++) {
|
|
89
|
+
for (let y = 0; y < size; y++) {
|
|
90
|
+
const value = cellData[(size - x - 1) * size + y];
|
|
91
|
+
const c = value === 0 ? bgColor : value === 1 ? color : spotColor;
|
|
92
|
+
for (let dx = 0; dx < scale; dx++) {
|
|
93
|
+
for (let dy = 0; dy < scale; dy++) {
|
|
94
|
+
const pixelIndex = (x * scale + dx) * rowDataSize + (y * scale + dy) * 3;
|
|
95
|
+
[2, 1, 0].forEach((offset, idx) => {
|
|
96
|
+
data[pixelIndex + offset] = c[idx];
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return data;
|
|
103
|
+
}
|
|
104
|
+
// Converts a number to little-endian hexadecimal format
|
|
105
|
+
static toLEHex(n) {
|
|
106
|
+
return (n + 2 ** 32).toString(16).match(/\B../g)?.reverse().join("") ?? "";
|
|
107
|
+
}
|
|
108
|
+
// Generates a BMP image data URL from pixel data
|
|
109
|
+
// The BMP format is constructed with a header and pixel data correctly padded.
|
|
110
|
+
// The header includes metadata such as size, width, height, and color depth.
|
|
111
|
+
static generateBMP(width, pixels) {
|
|
112
|
+
const height = Math.floor(pixels.length / (width * 3));
|
|
113
|
+
const size = this.toLEHex(26 + pixels.length);
|
|
114
|
+
const wh = this.toLEHex(width).slice(0, 4) + this.toLEHex(height).slice(0, 4);
|
|
115
|
+
const headerHex = `424d${size}000000001b0000000C000000${wh}0100180000`;
|
|
116
|
+
const headerBytes = headerHex.match(/../g)?.map(h => parseInt(h, 16)) ?? [];
|
|
117
|
+
const pixelChars = pixels.map(p => String.fromCharCode(p));
|
|
118
|
+
const base64Header = btoa(String.fromCharCode(...headerBytes));
|
|
119
|
+
const base64Pixels = btoa(pixelChars.join(""));
|
|
120
|
+
return `data:image/bmp;base64,${base64Header}${base64Pixels}`;
|
|
121
|
+
}
|
|
122
|
+
// Generates a BMP image data URL for the identicon
|
|
123
|
+
// The size and scale can be adjusted, with a default size of 8 and scale of 4.
|
|
124
|
+
// The generated image will have a symmetric pattern based on the seed string.
|
|
125
|
+
generate(size = 8, scale = 4) {
|
|
126
|
+
const mainColor = this.createColor();
|
|
127
|
+
const backgroundColor = this.createColor();
|
|
128
|
+
const spotColor = this.createColor();
|
|
129
|
+
const cellData = this.createImageData(size);
|
|
130
|
+
const pixelData = this.toPixels(size, cellData, scale, mainColor, spotColor, backgroundColor);
|
|
131
|
+
return IconGenerator.generateBMP(size * scale, pixelData);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=IconGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IconGenerator.js","sourceRoot":"","sources":["../../src/utils/IconGenerator.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,4FAA4F;AAC5F,uCAAuC;AACvC,MAAM,YAAY;IACR,KAAK,GAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAEvC,IAAI,CAAC,OAAe;QAClB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACxC,IAAI,CAAC,KAAK,CAAC,CAA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AW,CAAC,IAAI,GAAG,KAAK,EAAE,SAAS,CAAC,CAAC;IAC5D,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC;AAEhC,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAW/D"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getEnv } from "@ledgerhq/live-env";
|
|
2
|
+
export * from "./IconGenerator";
|
|
3
|
+
export function endpointByCurrencyId(currencyId) {
|
|
4
|
+
const endpoints = {
|
|
5
|
+
aptos: getEnv("APTOS_API_ENDPOINT"),
|
|
6
|
+
aptos_testnet: getEnv("APTOS_TESTNET_API_ENDPOINT"),
|
|
7
|
+
};
|
|
8
|
+
if (currencyId in endpoints) {
|
|
9
|
+
return endpoints[currencyId];
|
|
10
|
+
}
|
|
11
|
+
throw Error(`unexpected currency id format <${currencyId}>, should be like aptos[_testnet]`);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,cAAc,iBAAiB,CAAC;AAEhC,MAAM,UAAU,oBAAoB,CAAC,UAAkB;IACrD,MAAM,SAAS,GAA2B;QACxC,KAAK,EAAE,MAAM,CAAC,oBAAoB,CAAC;QACnC,aAAa,EAAE,MAAM,CAAC,4BAA4B,CAAC;KACpD,CAAC;IAEF,IAAI,UAAU,IAAI,SAAS,EAAE,CAAC;QAC5B,OAAO,SAAS,CAAC,UAAU,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM,KAAK,CAAC,kCAAkC,UAAU,mCAAmC,CAAC,CAAC;AAC/F,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-aptos",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.2-nightly.0",
|
|
4
4
|
"description": "Ledger Aptos Coin integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -69,6 +69,10 @@
|
|
|
69
69
|
"require": "./lib/types/index.js",
|
|
70
70
|
"default": "./lib-es/types/index.js"
|
|
71
71
|
},
|
|
72
|
+
"./utils": {
|
|
73
|
+
"require": "./lib/utils/index.js",
|
|
74
|
+
"default": "./lib-es/utils/index.js"
|
|
75
|
+
},
|
|
72
76
|
"./*": {
|
|
73
77
|
"require": "./lib/*.js",
|
|
74
78
|
"default": "./lib-es/*.js"
|
|
@@ -90,12 +94,13 @@
|
|
|
90
94
|
"invariant": "^2.2.4",
|
|
91
95
|
"lodash": "^4.17.21",
|
|
92
96
|
"rxjs": "^7.8.1",
|
|
93
|
-
"@ledgerhq/coin-framework": "^5.6.0",
|
|
94
|
-
"@ledgerhq/cryptoassets": "^13.
|
|
95
|
-
"@ledgerhq/
|
|
96
|
-
"@ledgerhq/
|
|
97
|
-
"@ledgerhq/
|
|
98
|
-
"@ledgerhq/live-
|
|
97
|
+
"@ledgerhq/coin-framework": "^5.6.1-nightly.0",
|
|
98
|
+
"@ledgerhq/cryptoassets": "^13.22.0-nightly.4",
|
|
99
|
+
"@ledgerhq/types-cryptoassets": "^7.23.0",
|
|
100
|
+
"@ledgerhq/devices": "8.4.8-nightly.0",
|
|
101
|
+
"@ledgerhq/errors": "^6.23.0-nightly.0",
|
|
102
|
+
"@ledgerhq/live-env": "^2.12.0-nightly.1",
|
|
103
|
+
"@ledgerhq/live-network": "^2.0.13-nightly.1",
|
|
99
104
|
"@ledgerhq/logs": "^6.13.0",
|
|
100
105
|
"@ledgerhq/types-live": "^6.77.0"
|
|
101
106
|
},
|
|
@@ -1,18 +1,130 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { createFixtureAccount, createFixtureTransaction } from "../../bridge/bridge.fixture";
|
|
3
|
+
import getDeviceTransactionConfig from "../../bridge/deviceTransactionConfig";
|
|
4
|
+
import { APTOS_PRECISION } from "../../constants";
|
|
5
|
+
|
|
6
|
+
const nonBreakableSpace = " ";
|
|
2
7
|
|
|
3
8
|
describe("deviceTransactionConfig", () => {
|
|
4
|
-
test("
|
|
5
|
-
|
|
6
|
-
|
|
9
|
+
test("coin transfer", () => {
|
|
10
|
+
const account = createFixtureAccount();
|
|
11
|
+
const parentAccount = null;
|
|
12
|
+
const transaction = createFixtureTransaction({
|
|
13
|
+
amount: BigNumber(123).shiftedBy(APTOS_PRECISION),
|
|
14
|
+
fees: BigNumber(456),
|
|
15
|
+
});
|
|
16
|
+
const fields = getDeviceTransactionConfig({
|
|
17
|
+
account,
|
|
18
|
+
parentAccount,
|
|
19
|
+
transaction,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
expect(fields).toMatchObject([
|
|
23
|
+
{
|
|
24
|
+
type: "text",
|
|
25
|
+
label: "Transaction Fee",
|
|
26
|
+
value: `0.00000456${nonBreakableSpace}APT`,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
type: "text",
|
|
30
|
+
label: "Amount",
|
|
31
|
+
value: `123${nonBreakableSpace}APT`,
|
|
32
|
+
},
|
|
33
|
+
]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("stake", () => {
|
|
37
|
+
const account = createFixtureAccount();
|
|
38
|
+
const parentAccount = null;
|
|
39
|
+
const transaction = createFixtureTransaction({
|
|
40
|
+
amount: BigNumber(123).shiftedBy(APTOS_PRECISION),
|
|
41
|
+
fees: BigNumber(456),
|
|
42
|
+
recipient: "delegator id",
|
|
43
|
+
mode: "stake",
|
|
44
|
+
});
|
|
45
|
+
const fields = getDeviceTransactionConfig({
|
|
46
|
+
account,
|
|
47
|
+
parentAccount,
|
|
48
|
+
transaction,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
expect(fields).toMatchObject([
|
|
52
|
+
{
|
|
53
|
+
type: "text",
|
|
54
|
+
label: "Transaction Fee",
|
|
55
|
+
value: `0.00000456${nonBreakableSpace}APT`,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
type: "text",
|
|
59
|
+
label: "Delegate to",
|
|
60
|
+
value: "delegator id",
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
type: "text",
|
|
64
|
+
label: "Amount",
|
|
65
|
+
value: `123${nonBreakableSpace}APT`,
|
|
66
|
+
},
|
|
67
|
+
]);
|
|
7
68
|
});
|
|
8
69
|
|
|
9
|
-
test("
|
|
10
|
-
const
|
|
70
|
+
test("unstake", () => {
|
|
71
|
+
const account = createFixtureAccount();
|
|
72
|
+
const parentAccount = null;
|
|
73
|
+
const transaction = createFixtureTransaction({
|
|
74
|
+
amount: BigNumber(123).shiftedBy(APTOS_PRECISION),
|
|
75
|
+
fees: BigNumber(456),
|
|
76
|
+
recipient: "delegator id",
|
|
77
|
+
mode: "unstake",
|
|
78
|
+
});
|
|
79
|
+
const fields = getDeviceTransactionConfig({
|
|
80
|
+
account,
|
|
81
|
+
parentAccount,
|
|
82
|
+
transaction,
|
|
83
|
+
});
|
|
84
|
+
|
|
11
85
|
expect(fields).toMatchObject([
|
|
12
86
|
{
|
|
13
87
|
type: "text",
|
|
14
|
-
label: "
|
|
15
|
-
value:
|
|
88
|
+
label: "Transaction Fee",
|
|
89
|
+
value: `0.00000456${nonBreakableSpace}APT`,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
type: "text",
|
|
93
|
+
label: "Undelegate from",
|
|
94
|
+
value: "delegator id",
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
type: "text",
|
|
98
|
+
label: "Amount",
|
|
99
|
+
value: `123${nonBreakableSpace}APT`,
|
|
100
|
+
},
|
|
101
|
+
]);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("unstake", () => {
|
|
105
|
+
const account = createFixtureAccount();
|
|
106
|
+
const parentAccount = null;
|
|
107
|
+
const transaction = createFixtureTransaction({
|
|
108
|
+
amount: BigNumber(123).shiftedBy(APTOS_PRECISION),
|
|
109
|
+
fees: BigNumber(456),
|
|
110
|
+
mode: "withdraw",
|
|
111
|
+
});
|
|
112
|
+
const fields = getDeviceTransactionConfig({
|
|
113
|
+
account,
|
|
114
|
+
parentAccount,
|
|
115
|
+
transaction,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
expect(fields).toMatchObject([
|
|
119
|
+
{
|
|
120
|
+
type: "text",
|
|
121
|
+
label: "Transaction Fee",
|
|
122
|
+
value: `0.00000456${nonBreakableSpace}APT`,
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
type: "text",
|
|
126
|
+
label: "Amount",
|
|
127
|
+
value: `123${nonBreakableSpace}APT`,
|
|
16
128
|
},
|
|
17
129
|
]);
|
|
18
130
|
});
|
|
@@ -66,9 +66,9 @@ describe("getFeesForTransaction Test", () => {
|
|
|
66
66
|
const result = await getFeesForTransaction.getFee(account, transaction, aptosClient);
|
|
67
67
|
|
|
68
68
|
const expected = {
|
|
69
|
-
fees: new BigNumber(
|
|
69
|
+
fees: new BigNumber(22644),
|
|
70
70
|
estimate: {
|
|
71
|
-
maxGasAmount: "
|
|
71
|
+
maxGasAmount: "222",
|
|
72
72
|
gasUnitPrice: "102",
|
|
73
73
|
},
|
|
74
74
|
errors: {},
|
|
@@ -100,9 +100,9 @@ describe("getFeesForTransaction Test", () => {
|
|
|
100
100
|
const result = await getFeesForTransaction.getFee(account, transaction, aptosClient);
|
|
101
101
|
|
|
102
102
|
const expected = {
|
|
103
|
-
fees: new BigNumber(
|
|
103
|
+
fees: new BigNumber(22644),
|
|
104
104
|
estimate: {
|
|
105
|
-
maxGasAmount: "
|
|
105
|
+
maxGasAmount: "222",
|
|
106
106
|
gasUnitPrice: "102",
|
|
107
107
|
},
|
|
108
108
|
errors: {},
|
|
@@ -210,9 +210,9 @@ describe("getFeesForTransaction Test", () => {
|
|
|
210
210
|
errors: {},
|
|
211
211
|
estimate: {
|
|
212
212
|
gasUnitPrice: "102",
|
|
213
|
-
maxGasAmount: "
|
|
213
|
+
maxGasAmount: "10",
|
|
214
214
|
},
|
|
215
|
-
fees: new BigNumber(
|
|
215
|
+
fees: new BigNumber(1020),
|
|
216
216
|
};
|
|
217
217
|
|
|
218
218
|
expect(result).toEqual(expected);
|
|
@@ -260,9 +260,9 @@ describe("getFeesForTransaction Test", () => {
|
|
|
260
260
|
errors: {},
|
|
261
261
|
estimate: {
|
|
262
262
|
gasUnitPrice: "102",
|
|
263
|
-
maxGasAmount: "
|
|
263
|
+
maxGasAmount: "222",
|
|
264
264
|
},
|
|
265
|
-
fees: new BigNumber(
|
|
265
|
+
fees: new BigNumber(22644),
|
|
266
266
|
};
|
|
267
267
|
|
|
268
268
|
expect(result1).toEqual(expected);
|
|
@@ -312,9 +312,9 @@ describe("getFeesForTransaction Test", () => {
|
|
|
312
312
|
errors: {},
|
|
313
313
|
estimate: {
|
|
314
314
|
gasUnitPrice: "102",
|
|
315
|
-
maxGasAmount: "
|
|
315
|
+
maxGasAmount: "222",
|
|
316
316
|
},
|
|
317
|
-
fees: new BigNumber(
|
|
317
|
+
fees: new BigNumber(22644),
|
|
318
318
|
};
|
|
319
319
|
|
|
320
320
|
expect(result1).toEqual(expected);
|