@ledgerhq/coin-canton 0.5.0-nightly.1 → 0.5.0-nightly.3
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/.turbo/turbo-build.log +1 -1
- package/.unimportedrc.json +12 -4
- package/CHANGELOG.md +32 -0
- package/lib/api/getBalance.integ.test.js +1 -1
- package/lib/api/getBalance.integ.test.js.map +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +11 -8
- package/lib/api/index.js.map +1 -1
- package/lib/bridge/broadcast.d.ts.map +1 -1
- package/lib/bridge/broadcast.js +2 -1
- package/lib/bridge/broadcast.js.map +1 -1
- package/lib/bridge/createTransaction.test.js +1 -1
- package/lib/bridge/createTransaction.test.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 -1
- package/lib/bridge/index.js.map +1 -1
- package/lib/bridge/onboard.d.ts +10 -0
- package/lib/bridge/onboard.d.ts.map +1 -0
- package/lib/bridge/onboard.integ.test.d.ts +2 -0
- package/lib/bridge/onboard.integ.test.d.ts.map +1 -0
- package/lib/bridge/onboard.integ.test.js +156 -0
- package/lib/bridge/onboard.integ.test.js.map +1 -0
- package/lib/bridge/onboard.js +139 -0
- package/lib/bridge/onboard.js.map +1 -0
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +5 -7
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +7 -9
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/sync.d.ts.map +1 -1
- package/lib/bridge/sync.integ.test.d.ts +2 -0
- package/lib/bridge/sync.integ.test.d.ts.map +1 -0
- package/lib/bridge/sync.integ.test.js +175 -0
- package/lib/bridge/sync.integ.test.js.map +1 -0
- package/lib/bridge/sync.js +40 -36
- package/lib/bridge/sync.js.map +1 -1
- package/lib/bridge/updateTransaction.d.ts.map +1 -1
- package/lib/bridge/updateTransaction.js +0 -4
- package/lib/bridge/updateTransaction.js.map +1 -1
- package/lib/common-logic/history/listOperations.d.ts.map +1 -1
- package/lib/common-logic/history/listOperations.js +19 -31
- package/lib/common-logic/history/listOperations.js.map +1 -1
- package/lib/common-logic/transaction/broadcast.d.ts.map +1 -1
- package/lib/common-logic/transaction/broadcast.js +2 -1
- package/lib/common-logic/transaction/broadcast.js.map +1 -1
- package/lib/common-logic/transaction/broadcast.test.js +3 -3
- package/lib/common-logic/transaction/broadcast.test.js.map +1 -1
- package/lib/common-logic/transaction/combine.d.ts +1 -1
- package/lib/common-logic/transaction/combine.d.ts.map +1 -1
- package/lib/common-logic/transaction/combine.js +2 -3
- package/lib/common-logic/transaction/combine.js.map +1 -1
- package/lib/common-logic/transaction/combine.test.js +3 -13
- package/lib/common-logic/transaction/combine.test.js.map +1 -1
- package/lib/common-logic/transaction/craftTransaction.d.ts +5 -3
- package/lib/common-logic/transaction/craftTransaction.d.ts.map +1 -1
- package/lib/common-logic/transaction/craftTransaction.js +11 -12
- package/lib/common-logic/transaction/craftTransaction.js.map +1 -1
- package/lib/network/gateway.d.ts +196 -5
- package/lib/network/gateway.d.ts.map +1 -1
- package/lib/network/gateway.integ.test.js +121 -11
- package/lib/network/gateway.integ.test.js.map +1 -1
- package/lib/network/gateway.js +99 -21
- package/lib/network/gateway.js.map +1 -1
- package/lib/network/node.d.ts +2 -2
- package/lib/network/node.d.ts.map +1 -1
- package/lib/network/node.js.map +1 -1
- package/lib/network/types.d.ts +1 -1
- package/lib/network/types.d.ts.map +1 -1
- package/lib/signer/getAddress.d.ts.map +1 -1
- package/lib/signer/getAddress.js +2 -2
- package/lib/signer/getAddress.js.map +1 -1
- package/lib/test/cantonTestUtils.d.ts +33 -0
- package/lib/test/cantonTestUtils.d.ts.map +1 -0
- package/lib/test/cantonTestUtils.js +159 -0
- package/lib/test/cantonTestUtils.js.map +1 -0
- package/lib/types/bridge.d.ts +7 -1
- package/lib/types/bridge.d.ts.map +1 -1
- package/lib/types/index.d.ts +1 -10
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +1 -0
- package/lib/types/index.js.map +1 -1
- package/lib/types/onboard.d.ts +55 -0
- package/lib/types/onboard.d.ts.map +1 -0
- package/lib/types/onboard.js +22 -0
- package/lib/types/onboard.js.map +1 -0
- package/lib-es/api/getBalance.integ.test.js +1 -1
- package/lib-es/api/getBalance.integ.test.js.map +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +12 -9
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/bridge/broadcast.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.js +2 -1
- package/lib-es/bridge/broadcast.js.map +1 -1
- package/lib-es/bridge/createTransaction.test.js +1 -1
- package/lib-es/bridge/createTransaction.test.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 -1
- package/lib-es/bridge/index.js.map +1 -1
- package/lib-es/bridge/onboard.d.ts +10 -0
- package/lib-es/bridge/onboard.d.ts.map +1 -0
- package/lib-es/bridge/onboard.integ.test.d.ts +2 -0
- package/lib-es/bridge/onboard.integ.test.d.ts.map +1 -0
- package/lib-es/bridge/onboard.integ.test.js +151 -0
- package/lib-es/bridge/onboard.integ.test.js.map +1 -0
- package/lib-es/bridge/onboard.js +133 -0
- package/lib-es/bridge/onboard.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +6 -8
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/signOperation.d.ts.map +1 -1
- package/lib-es/bridge/signOperation.js +8 -10
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/sync.d.ts.map +1 -1
- package/lib-es/bridge/sync.integ.test.d.ts +2 -0
- package/lib-es/bridge/sync.integ.test.d.ts.map +1 -0
- package/lib-es/bridge/sync.integ.test.js +137 -0
- package/lib-es/bridge/sync.integ.test.js.map +1 -0
- package/lib-es/bridge/sync.js +39 -35
- package/lib-es/bridge/sync.js.map +1 -1
- package/lib-es/bridge/updateTransaction.d.ts.map +1 -1
- package/lib-es/bridge/updateTransaction.js +0 -4
- package/lib-es/bridge/updateTransaction.js.map +1 -1
- package/lib-es/common-logic/history/listOperations.d.ts.map +1 -1
- package/lib-es/common-logic/history/listOperations.js +20 -29
- package/lib-es/common-logic/history/listOperations.js.map +1 -1
- package/lib-es/common-logic/transaction/broadcast.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/broadcast.js +2 -1
- package/lib-es/common-logic/transaction/broadcast.js.map +1 -1
- package/lib-es/common-logic/transaction/broadcast.test.js +3 -3
- package/lib-es/common-logic/transaction/broadcast.test.js.map +1 -1
- package/lib-es/common-logic/transaction/combine.d.ts +1 -1
- package/lib-es/common-logic/transaction/combine.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/combine.js +2 -3
- package/lib-es/common-logic/transaction/combine.js.map +1 -1
- package/lib-es/common-logic/transaction/combine.test.js +3 -13
- package/lib-es/common-logic/transaction/combine.test.js.map +1 -1
- package/lib-es/common-logic/transaction/craftTransaction.d.ts +5 -3
- package/lib-es/common-logic/transaction/craftTransaction.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/craftTransaction.js +11 -12
- package/lib-es/common-logic/transaction/craftTransaction.js.map +1 -1
- package/lib-es/network/gateway.d.ts +196 -5
- package/lib-es/network/gateway.d.ts.map +1 -1
- package/lib-es/network/gateway.integ.test.js +122 -12
- package/lib-es/network/gateway.integ.test.js.map +1 -1
- package/lib-es/network/gateway.js +93 -20
- package/lib-es/network/gateway.js.map +1 -1
- package/lib-es/network/node.d.ts +2 -2
- package/lib-es/network/node.d.ts.map +1 -1
- package/lib-es/network/node.js.map +1 -1
- package/lib-es/network/types.d.ts +1 -1
- package/lib-es/network/types.d.ts.map +1 -1
- package/lib-es/signer/getAddress.d.ts.map +1 -1
- package/lib-es/signer/getAddress.js +2 -2
- package/lib-es/signer/getAddress.js.map +1 -1
- package/lib-es/test/cantonTestUtils.d.ts +33 -0
- package/lib-es/test/cantonTestUtils.d.ts.map +1 -0
- package/lib-es/test/cantonTestUtils.js +151 -0
- package/lib-es/test/cantonTestUtils.js.map +1 -0
- package/lib-es/types/bridge.d.ts +7 -1
- package/lib-es/types/bridge.d.ts.map +1 -1
- package/lib-es/types/index.d.ts +1 -10
- package/lib-es/types/index.d.ts.map +1 -1
- package/lib-es/types/index.js +1 -0
- package/lib-es/types/index.js.map +1 -1
- package/lib-es/types/onboard.d.ts +55 -0
- package/lib-es/types/onboard.d.ts.map +1 -0
- package/lib-es/types/onboard.js +19 -0
- package/lib-es/types/onboard.js.map +1 -0
- package/package.json +7 -7
- package/src/api/getBalance.integ.test.ts +1 -2
- package/src/api/index.ts +33 -26
- package/src/bridge/broadcast.ts +2 -3
- package/src/bridge/createTransaction.test.ts +1 -1
- package/src/bridge/index.ts +14 -4
- package/src/bridge/onboard.integ.test.ts +219 -0
- package/src/bridge/onboard.ts +220 -0
- package/src/bridge/prepareTransaction.ts +6 -15
- package/src/bridge/signOperation.ts +9 -16
- package/src/bridge/sync.integ.test.ts +180 -0
- package/src/bridge/sync.ts +61 -49
- package/src/bridge/updateTransaction.ts +0 -5
- package/src/common-logic/history/listOperations.ts +20 -31
- package/src/common-logic/transaction/broadcast.test.ts +3 -3
- package/src/common-logic/transaction/broadcast.ts +2 -1
- package/src/common-logic/transaction/combine.test.ts +3 -13
- package/src/common-logic/transaction/combine.ts +2 -4
- package/src/common-logic/transaction/craftTransaction.ts +15 -17
- package/src/network/gateway.integ.test.ts +156 -17
- package/src/network/gateway.ts +337 -30
- package/src/network/node.ts +3 -3
- package/src/network/types.ts +1 -1
- package/src/signer/getAddress.ts +3 -5
- package/src/test/cantonTestUtils.ts +181 -0
- package/src/types/bridge.ts +20 -0
- package/src/types/index.ts +1 -11
- package/src/types/onboard.ts +65 -0
package/src/network/node.ts
CHANGED
|
@@ -3,7 +3,7 @@ import network from "@ledgerhq/live-network";
|
|
|
3
3
|
import type { LiveNetworkRequest } from "@ledgerhq/live-network/network";
|
|
4
4
|
import { getEnv } from "@ledgerhq/live-env";
|
|
5
5
|
import coinConfig from "../config";
|
|
6
|
-
import { AccountInfoResponse,
|
|
6
|
+
import { AccountInfoResponse, SubmitResponse } from "./types";
|
|
7
7
|
import crypto from "crypto";
|
|
8
8
|
|
|
9
9
|
const getNodeUrl = () => coinConfig.getCoinConfig().nodeUrl || "";
|
|
@@ -86,10 +86,10 @@ export const getLedgerEnd = async (): Promise<number> => {
|
|
|
86
86
|
return data.offset;
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
-
export const submit = async (signedTx: string): Promise<
|
|
89
|
+
export const submit = async (signedTx: string): Promise<SubmitResponse> => {
|
|
90
90
|
// @ts-expect-error: add NODE_BOILERPLATE to libs/env/src/env.ts
|
|
91
91
|
const url = `${getEnv("NODE_BOILERPLATE")}/submit`;
|
|
92
|
-
const { data } = await network<
|
|
92
|
+
const { data } = await network<SubmitResponse>({
|
|
93
93
|
url,
|
|
94
94
|
method: "GET",
|
|
95
95
|
});
|
package/src/network/types.ts
CHANGED
package/src/signer/getAddress.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { GetAddressOptions } from "@ledgerhq/coin-framework/derivation";
|
|
2
2
|
import { GetAddressFn } from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
3
3
|
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
4
|
-
import {
|
|
4
|
+
import { CantonSigner } from "../types";
|
|
5
5
|
|
|
6
6
|
const getAddress = (signerContext: SignerContext<CantonSigner>): GetAddressFn => {
|
|
7
|
-
return async (deviceId: string, { path
|
|
8
|
-
const { address, publicKey } =
|
|
9
|
-
signer.getAddress(path),
|
|
10
|
-
)) as CantonAddress;
|
|
7
|
+
return async (deviceId: string, { path }: GetAddressOptions) => {
|
|
8
|
+
const { address, publicKey } = await signerContext(deviceId, signer => signer.getAddress(path));
|
|
11
9
|
|
|
12
10
|
return {
|
|
13
11
|
path,
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canton Testing Utilities for Ed25519 Key Generation
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities to generate proper Ed25519 keypairs for testing Canton
|
|
5
|
+
* onboarding without requiring physical Ledger devices.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import crypto from "crypto";
|
|
9
|
+
|
|
10
|
+
export interface CantonTestKeyPair {
|
|
11
|
+
publicKeyHex: string; // Ready for Canton Gateway API
|
|
12
|
+
privateKeyHex: string; // ASN.1 DER encoded private key in hex format
|
|
13
|
+
privateKeyPem: string; // PEM format for signing operations
|
|
14
|
+
fingerprint: string; // Canton public key fingerprint (multihash: 1220 + SHA256(publicKey))
|
|
15
|
+
sign: (hashHex: string) => string; // Sign transaction hash
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Generate fresh Ed25519 keypair
|
|
20
|
+
*/
|
|
21
|
+
export function generateMockKeyPair(): CantonTestKeyPair {
|
|
22
|
+
const { publicKey, privateKey } = crypto.generateKeyPairSync("ed25519");
|
|
23
|
+
|
|
24
|
+
const publicKeyBuffer = publicKey.export({ type: "spki", format: "der" });
|
|
25
|
+
const rawPublicKey = publicKeyBuffer.slice(-32);
|
|
26
|
+
const publicKeyHex = rawPublicKey.toString("hex");
|
|
27
|
+
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
29
|
+
const privateKeyPem = privateKey.export({ type: "pkcs8", format: "pem" }) as string;
|
|
30
|
+
const privateKeyDer = privateKey.export({ type: "pkcs8", format: "der" });
|
|
31
|
+
const privateKeyHex = privateKeyDer.toString("hex");
|
|
32
|
+
|
|
33
|
+
// Generate fingerprint: Canton computes SHA256(purpose_bytes + public_key_bytes)
|
|
34
|
+
// where purpose_bytes is 4-byte big-endian representation of PURPOSE_PUBLIC_KEY_FINGERPRINT (12)
|
|
35
|
+
const PURPOSE_PUBLIC_KEY_FINGERPRINT = 12;
|
|
36
|
+
const purposeBytes = Buffer.allocUnsafe(4);
|
|
37
|
+
purposeBytes.writeInt32BE(PURPOSE_PUBLIC_KEY_FINGERPRINT, 0);
|
|
38
|
+
|
|
39
|
+
const hash = crypto.createHash("sha256");
|
|
40
|
+
hash.update(purposeBytes);
|
|
41
|
+
hash.update(rawPublicKey);
|
|
42
|
+
const hashedContent = hash.digest();
|
|
43
|
+
|
|
44
|
+
// Multihash encoding: 0x12 (SHA256) + 0x20 (32 bytes) + hash
|
|
45
|
+
const multihashPrefix = Buffer.from([0x12, 0x20]);
|
|
46
|
+
const fingerprintBuffer = Buffer.concat([multihashPrefix, hashedContent]);
|
|
47
|
+
const fingerprint = fingerprintBuffer.toString("hex");
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
publicKeyHex, // 64-char hex string (no 0x prefix)
|
|
51
|
+
privateKeyHex, // ASN.1 DER encoded private key in hex format
|
|
52
|
+
privateKeyPem, // PEM format string
|
|
53
|
+
fingerprint, // Canton format: multihash prefix + SHA256(public key)
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Sign a transaction hash using proper Ed25519 signature
|
|
57
|
+
*/
|
|
58
|
+
sign: (hashHex: string): string => {
|
|
59
|
+
const hashBuffer = Buffer.from(hashHex, "hex");
|
|
60
|
+
const privateKeyObj = crypto.createPrivateKey({
|
|
61
|
+
key: privateKeyPem,
|
|
62
|
+
format: "pem",
|
|
63
|
+
type: "pkcs8",
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const signature = crypto.sign(null, hashBuffer, privateKeyObj);
|
|
67
|
+
return signature.toString("hex");
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Verify Ed25519 signature against public key and message hash
|
|
74
|
+
*/
|
|
75
|
+
export function verifySignature(
|
|
76
|
+
publicKeyHex: string,
|
|
77
|
+
signatureHex: string,
|
|
78
|
+
messageHashHex: string,
|
|
79
|
+
): { isValid: boolean; error?: string; details: any } {
|
|
80
|
+
try {
|
|
81
|
+
// Clean inputs - remove 0x prefixes if present
|
|
82
|
+
const cleanPublicKey = publicKeyHex.startsWith("0x") ? publicKeyHex.slice(2) : publicKeyHex;
|
|
83
|
+
const cleanSignature = signatureHex.startsWith("0x") ? signatureHex.slice(2) : signatureHex;
|
|
84
|
+
const cleanMessageHash = messageHashHex.startsWith("0x")
|
|
85
|
+
? messageHashHex.slice(2)
|
|
86
|
+
: messageHashHex;
|
|
87
|
+
|
|
88
|
+
const details: any = {
|
|
89
|
+
publicKeyLength: cleanPublicKey.length,
|
|
90
|
+
signatureLength: cleanSignature.length,
|
|
91
|
+
messageHashLength: cleanMessageHash.length,
|
|
92
|
+
publicKeyBytes: cleanPublicKey.length / 2,
|
|
93
|
+
signatureBytes: cleanSignature.length / 2,
|
|
94
|
+
messageHashBytes: cleanMessageHash.length / 2,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// Validate input lengths
|
|
98
|
+
if (cleanPublicKey.length !== 64) {
|
|
99
|
+
return {
|
|
100
|
+
isValid: false,
|
|
101
|
+
error: `Invalid public key length: expected 64 hex chars (32 bytes), got ${cleanPublicKey.length}`,
|
|
102
|
+
details,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Ed25519 signatures should be 64 bytes, but we might receive 65 bytes with recovery ID
|
|
107
|
+
let processedSignature = cleanSignature;
|
|
108
|
+
if (cleanSignature.length === 130) {
|
|
109
|
+
processedSignature = cleanSignature.slice(2, -2);
|
|
110
|
+
details.originalSignatureLength = cleanSignature.length;
|
|
111
|
+
details.processedSignatureLength = processedSignature.length;
|
|
112
|
+
} else if (cleanSignature.length !== 128) {
|
|
113
|
+
return {
|
|
114
|
+
isValid: false,
|
|
115
|
+
error: `Invalid signature length: expected 128 hex chars (64 bytes) or 130 hex chars (65 bytes), got ${cleanSignature.length}`,
|
|
116
|
+
details,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Convert hex to buffers
|
|
121
|
+
const publicKeyBuffer = Buffer.from(cleanPublicKey, "hex");
|
|
122
|
+
const signatureBuffer = Buffer.from(processedSignature, "hex");
|
|
123
|
+
const messageBuffer = Buffer.from(cleanMessageHash, "hex");
|
|
124
|
+
|
|
125
|
+
// Create public key object for verification
|
|
126
|
+
// Ed25519 public keys need to be wrapped in SPKI format for Node.js crypto
|
|
127
|
+
const spkiHeader = Buffer.from([
|
|
128
|
+
0x30,
|
|
129
|
+
0x2a, // SEQUENCE, length 42
|
|
130
|
+
0x30,
|
|
131
|
+
0x05, // SEQUENCE, length 5
|
|
132
|
+
0x06,
|
|
133
|
+
0x03,
|
|
134
|
+
0x2b,
|
|
135
|
+
0x65,
|
|
136
|
+
0x70, // OID for Ed25519
|
|
137
|
+
0x03,
|
|
138
|
+
0x21,
|
|
139
|
+
0x00, // BIT STRING, length 33, no unused bits
|
|
140
|
+
]);
|
|
141
|
+
const spkiPublicKey = Buffer.concat([spkiHeader, publicKeyBuffer]);
|
|
142
|
+
|
|
143
|
+
const publicKeyObj = crypto.createPublicKey({
|
|
144
|
+
key: spkiPublicKey,
|
|
145
|
+
format: "der",
|
|
146
|
+
type: "spki",
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// Verify signature
|
|
150
|
+
const isValid = crypto.verify(null, messageBuffer, publicKeyObj, signatureBuffer);
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
isValid,
|
|
154
|
+
details: {
|
|
155
|
+
...details,
|
|
156
|
+
processedSignatureLength: processedSignature.length,
|
|
157
|
+
verificationMethod: "Node.js crypto.verify with Ed25519",
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
} catch (error) {
|
|
161
|
+
return {
|
|
162
|
+
isValid: false,
|
|
163
|
+
error: `Verification failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
164
|
+
details: { error: String(error) },
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function createMockSigner(keyPair: CantonTestKeyPair) {
|
|
170
|
+
return {
|
|
171
|
+
getAddress: async (derivationPath: string) => ({
|
|
172
|
+
address: `canton_test_${keyPair.fingerprint.slice(-8)}`,
|
|
173
|
+
publicKey: keyPair.publicKeyHex,
|
|
174
|
+
}),
|
|
175
|
+
|
|
176
|
+
signTransaction: async (derivationPath: string, hashToSign: string) => {
|
|
177
|
+
const cleanHash = hashToSign.startsWith("0x") ? hashToSign.slice(2) : hashToSign;
|
|
178
|
+
return keyPair.sign(cleanHash);
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
package/src/types/bridge.ts
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
import type { BigNumber } from "bignumber.js";
|
|
2
|
+
import type { Observable } from "rxjs";
|
|
2
3
|
import type {
|
|
4
|
+
CurrencyBridge,
|
|
3
5
|
TransactionCommon,
|
|
4
6
|
TransactionCommonRaw,
|
|
5
7
|
TransactionStatusCommon,
|
|
6
8
|
TransactionStatusCommonRaw,
|
|
7
9
|
} from "@ledgerhq/types-live";
|
|
10
|
+
import type {
|
|
11
|
+
CantonOnboardProgress,
|
|
12
|
+
CantonOnboardResult,
|
|
13
|
+
CantonPreApprovalProgress,
|
|
14
|
+
CantonPreApprovalResult,
|
|
15
|
+
} from "./onboard";
|
|
16
|
+
|
|
17
|
+
export interface CantonCurrencyBridge extends CurrencyBridge {
|
|
18
|
+
onboardAccount: (
|
|
19
|
+
deviceId: string,
|
|
20
|
+
derivationPath: string,
|
|
21
|
+
) => Observable<CantonOnboardProgress | CantonOnboardResult>;
|
|
22
|
+
authorizePreapproval: (
|
|
23
|
+
deviceId: string,
|
|
24
|
+
derivationPath: string,
|
|
25
|
+
partyId: string,
|
|
26
|
+
) => Observable<CantonPreApprovalProgress | CantonPreApprovalResult>;
|
|
27
|
+
}
|
|
8
28
|
|
|
9
29
|
export type NetworkInfo = {
|
|
10
30
|
family: "canton";
|
package/src/types/index.ts
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
1
|
export * from "./bridge";
|
|
2
|
+
export * from "./onboard";
|
|
2
3
|
export * from "./signer";
|
|
3
|
-
|
|
4
|
-
export type BoilerplateNativeTransaction = {
|
|
5
|
-
TransactionType: "Payment";
|
|
6
|
-
Account: string;
|
|
7
|
-
Amount: string;
|
|
8
|
-
Destination: string;
|
|
9
|
-
Fee: string;
|
|
10
|
-
Sequence: number;
|
|
11
|
-
SigningPubKey?: string;
|
|
12
|
-
TxnSignature?: string;
|
|
13
|
-
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export enum OnboardStatus {
|
|
2
|
+
INIT,
|
|
3
|
+
PREPARE,
|
|
4
|
+
SIGN,
|
|
5
|
+
SUBMIT,
|
|
6
|
+
SUCCESS,
|
|
7
|
+
ERROR,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export enum PreApprovalStatus {
|
|
11
|
+
INIT,
|
|
12
|
+
PREPARE,
|
|
13
|
+
SIGN,
|
|
14
|
+
SUBMIT,
|
|
15
|
+
SUCCESS,
|
|
16
|
+
ERROR,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type CantonOnboardProgress = {
|
|
20
|
+
status: OnboardStatus;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type CantonOnboardResult = {
|
|
24
|
+
partyId: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type CantonPreApprovalProgress = {
|
|
28
|
+
status: PreApprovalStatus;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type CantonPreApprovalResult = {
|
|
32
|
+
isApproved: boolean;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Types for Canton Gateway Transaction API
|
|
37
|
+
* Based on the API endpoints in canton-gateway
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
export interface PrepareTransactionRequest {
|
|
41
|
+
type: "transfer-pre-approval-proposal";
|
|
42
|
+
receiver: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface PrepareTransactionResponse {
|
|
46
|
+
serialized: string; // Hex-encoded serialized protobuf
|
|
47
|
+
json: any; // JSON representation
|
|
48
|
+
hash: string; // Transaction hash for signing
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface SubmitTransactionRequest {
|
|
52
|
+
serialized: string; // Hex-encoded serialized protobuf
|
|
53
|
+
signature: string; // Hex-encoded signature
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface SubmitTransactionResponse {
|
|
57
|
+
submission_id: string;
|
|
58
|
+
update_id: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface PreApprovalResult {
|
|
62
|
+
isApproved: boolean;
|
|
63
|
+
submissionId: string;
|
|
64
|
+
updateId: string;
|
|
65
|
+
}
|