@canton-network/core-signing-lib 1.8.0 → 1.9.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/dist/index.cjs +85 -76
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +59 -68
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -1,91 +1,100 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let tweetnacl = require("tweetnacl");
|
|
25
|
+
tweetnacl = __toESM(tweetnacl, 1);
|
|
26
|
+
let tweetnacl_util = require("tweetnacl-util");
|
|
27
|
+
tweetnacl_util = __toESM(tweetnacl_util, 1);
|
|
28
|
+
let zod = require("zod");
|
|
29
|
+
//#region src/config/schema.ts
|
|
30
|
+
let SigningProvider = /* @__PURE__ */ function(SigningProvider) {
|
|
31
|
+
SigningProvider["WALLET_KERNEL"] = "wallet-kernel";
|
|
32
|
+
SigningProvider["PARTICIPANT"] = "participant";
|
|
33
|
+
SigningProvider["FIREBLOCKS"] = "fireblocks";
|
|
34
|
+
SigningProvider["BLOCKDAEMON"] = "blockdaemon";
|
|
35
|
+
SigningProvider["DFNS"] = "dfns";
|
|
36
|
+
return SigningProvider;
|
|
37
|
+
}({});
|
|
38
|
+
const signingDriverConfigSchema = zod.z.object({
|
|
39
|
+
provider: zod.z.nativeEnum(SigningProvider),
|
|
40
|
+
properties: zod.z.record(zod.z.string(), zod.z.any()).optional()
|
|
27
41
|
});
|
|
28
|
-
|
|
29
|
-
|
|
42
|
+
const signingConfigSchema = zod.z.object({ drivers: zod.z.array(signingDriverConfigSchema).optional() });
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/rpc-gen/index.ts
|
|
30
45
|
function buildController(methods) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
return {
|
|
47
|
+
signTransaction: methods.signTransaction,
|
|
48
|
+
signMessage: methods.signMessage,
|
|
49
|
+
getTransaction: methods.getTransaction,
|
|
50
|
+
getTransactions: methods.getTransactions,
|
|
51
|
+
getKeys: methods.getKeys,
|
|
52
|
+
createKey: methods.createKey,
|
|
53
|
+
getConfiguration: methods.getConfiguration,
|
|
54
|
+
setConfiguration: methods.setConfiguration,
|
|
55
|
+
subscribeTransactions: methods.subscribeTransactions
|
|
56
|
+
};
|
|
42
57
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var CC_COIN_TYPE = 6767;
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/index.ts
|
|
60
|
+
const CC_COIN_TYPE = 6767;
|
|
47
61
|
function isRpcError(value) {
|
|
48
|
-
|
|
62
|
+
return value.error_description !== void 0;
|
|
49
63
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
naclUtil__default.default.decodeBase64(txHash),
|
|
58
|
-
naclUtil__default.default.decodeBase64(signature),
|
|
59
|
-
naclUtil__default.default.decodeBase64(publicKey)
|
|
60
|
-
);
|
|
64
|
+
let PartyMode = /* @__PURE__ */ function(PartyMode) {
|
|
65
|
+
PartyMode["INTERNAL"] = "internal";
|
|
66
|
+
PartyMode["EXTERNAL"] = "external";
|
|
67
|
+
return PartyMode;
|
|
68
|
+
}({});
|
|
69
|
+
const verifySignedTxHash = (txHash, publicKey, signature) => {
|
|
70
|
+
return tweetnacl.default.sign.detached.verify(tweetnacl_util.default.decodeBase64(txHash), tweetnacl_util.default.decodeBase64(signature), tweetnacl_util.default.decodeBase64(publicKey));
|
|
61
71
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
nacl__default.default.sign.detached(naclUtil__default.default.decodeBase64(txHash), decodedKey)
|
|
66
|
-
);
|
|
72
|
+
const signTransactionHash = (txHash, privateKey) => {
|
|
73
|
+
const decodedKey = tweetnacl_util.default.decodeBase64(privateKey);
|
|
74
|
+
return tweetnacl_util.default.encodeBase64(tweetnacl.default.sign.detached(tweetnacl_util.default.decodeBase64(txHash), decodedKey));
|
|
67
75
|
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
76
|
+
const signMessage = (message, privateKey) => {
|
|
77
|
+
const msgBytes = new TextEncoder().encode(message);
|
|
78
|
+
const decodedKey = tweetnacl_util.default.decodeBase64(privateKey);
|
|
79
|
+
return tweetnacl_util.default.encodeBase64(tweetnacl.default.sign.detached(msgBytes, decodedKey));
|
|
72
80
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
81
|
+
const getPublicKeyFromPrivate = (privateKeyBase64) => {
|
|
82
|
+
const secretKey = tweetnacl_util.default.decodeBase64(privateKeyBase64);
|
|
83
|
+
const keyPair = tweetnacl.default.sign.keyPair.fromSecretKey(secretKey);
|
|
84
|
+
return tweetnacl_util.default.encodeBase64(keyPair.publicKey);
|
|
77
85
|
};
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
86
|
+
const createKeyPair = () => {
|
|
87
|
+
const key = tweetnacl.default.sign.keyPair();
|
|
88
|
+
return {
|
|
89
|
+
publicKey: tweetnacl_util.default.encodeBase64(key.publicKey),
|
|
90
|
+
privateKey: tweetnacl_util.default.encodeBase64(key.secretKey)
|
|
91
|
+
};
|
|
83
92
|
};
|
|
84
|
-
|
|
93
|
+
//#endregion
|
|
85
94
|
exports.CC_COIN_TYPE = CC_COIN_TYPE;
|
|
86
95
|
exports.PartyMode = PartyMode;
|
|
87
96
|
exports.SigningProvider = SigningProvider;
|
|
88
|
-
exports.buildController =
|
|
97
|
+
exports.buildController = buildController;
|
|
89
98
|
exports.createKeyPair = createKeyPair;
|
|
90
99
|
exports.getPublicKeyFromPrivate = getPublicKeyFromPrivate;
|
|
91
100
|
exports.isRpcError = isRpcError;
|
|
@@ -94,5 +103,5 @@ exports.signTransactionHash = signTransactionHash;
|
|
|
94
103
|
exports.signingConfigSchema = signingConfigSchema;
|
|
95
104
|
exports.signingDriverConfigSchema = signingDriverConfigSchema;
|
|
96
105
|
exports.verifySignedTxHash = verifySignedTxHash;
|
|
97
|
-
|
|
106
|
+
|
|
98
107
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["z","nacl","naclUtil"],"sources":["../src/config/schema.ts","../src/rpc-gen/index.ts","../src/index.ts"],"sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { z } from 'zod'\n\nexport enum SigningProvider {\n WALLET_KERNEL = 'wallet-kernel',\n PARTICIPANT = 'participant',\n FIREBLOCKS = 'fireblocks',\n BLOCKDAEMON = 'blockdaemon',\n DFNS = 'dfns',\n}\n\n// Generic signing driver configuration schema\nexport const signingDriverConfigSchema = z.object({\n provider: z.nativeEnum(SigningProvider),\n properties: z.record(z.string(), z.any()).optional(),\n})\n\n// Top-level Signing Configuration Schema - array of driver configs\nexport const signingConfigSchema = z.object({\n drivers: z.array(signingDriverConfigSchema).optional(),\n})\n\n// Type exports\nexport type SigningDriverAppConfig = z.infer<typeof signingDriverConfigSchema>\nexport type SigningConfig = z.infer<typeof signingConfigSchema>\n","// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { SignTransaction } from './typings.js'\nimport { SignMessage } from './typings.js'\nimport { GetTransaction } from './typings.js'\nimport { GetTransactions } from './typings.js'\nimport { GetKeys } from './typings.js'\nimport { CreateKey } from './typings.js'\nimport { GetConfiguration } from './typings.js'\nimport { SetConfiguration } from './typings.js'\nimport { SubscribeTransactions } from './typings.js'\n\nexport type Methods = {\n signTransaction: SignTransaction\n signMessage: SignMessage\n getTransaction: GetTransaction\n getTransactions: GetTransactions\n getKeys: GetKeys\n createKey: CreateKey\n getConfiguration: GetConfiguration\n setConfiguration: SetConfiguration\n subscribeTransactions: SubscribeTransactions\n}\n\nfunction buildController(methods: Methods) {\n return {\n signTransaction: methods.signTransaction,\n signMessage: methods.signMessage,\n getTransaction: methods.getTransaction,\n getTransactions: methods.getTransactions,\n getKeys: methods.getKeys,\n createKey: methods.createKey,\n getConfiguration: methods.getConfiguration,\n setConfiguration: methods.setConfiguration,\n subscribeTransactions: methods.subscribeTransactions,\n }\n}\n\nexport default buildController\n","// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { AuthContext } from '@canton-network/core-wallet-auth'\nimport { Methods } from './rpc-gen/index.js'\nimport { Error as RpcError } from './rpc-gen/typings.js'\nimport nacl from 'tweetnacl'\nimport naclUtil from 'tweetnacl-util'\nimport { SigningProvider } from './config/schema.js'\n\n// Re-export SigningProvider from config schema\nexport { SigningProvider }\n\nexport { default as buildController, type Methods } from './rpc-gen/index.js'\nexport * from './rpc-gen/typings.js'\nexport * from './SigningDriverStore.js'\nexport * from './config/schema.js'\n\nexport const CC_COIN_TYPE = 6767\n\nexport function isRpcError<T>(value: T | RpcError): value is RpcError {\n return (value as RpcError).error_description !== undefined\n}\n\nexport enum PartyMode {\n INTERNAL = 'internal',\n EXTERNAL = 'external',\n}\n\nexport type PublicKey = string\nexport type PrivateKey = string\n\nexport interface KeyPair {\n publicKey: PublicKey\n privateKey: PrivateKey\n}\n\nexport interface SigningDriverInterface {\n partyMode: PartyMode\n signingProvider: SigningProvider\n controller: (userId: AuthContext['userId'] | undefined) => Methods\n}\n\nexport const verifySignedTxHash = (\n txHash: string,\n publicKey: string,\n signature: string\n): boolean => {\n return nacl.sign.detached.verify(\n naclUtil.decodeBase64(txHash),\n naclUtil.decodeBase64(signature),\n naclUtil.decodeBase64(publicKey)\n )\n}\n\nexport const signTransactionHash = (\n txHash: string,\n privateKey: string\n): string => {\n const decodedKey = naclUtil.decodeBase64(privateKey)\n\n return naclUtil.encodeBase64(\n nacl.sign.detached(naclUtil.decodeBase64(txHash), decodedKey)\n )\n}\n\nexport const signMessage = (message: string, privateKey: string): string => {\n const msgBytes = new TextEncoder().encode(message)\n const decodedKey = naclUtil.decodeBase64(privateKey)\n return naclUtil.encodeBase64(nacl.sign.detached(msgBytes, decodedKey))\n}\n\nexport const getPublicKeyFromPrivate = (privateKeyBase64: string): string => {\n const secretKey = naclUtil.decodeBase64(privateKeyBase64)\n const keyPair = nacl.sign.keyPair.fromSecretKey(secretKey)\n return naclUtil.encodeBase64(keyPair.publicKey)\n}\n\nexport const createKeyPair = (): KeyPair => {\n const key = nacl.sign.keyPair()\n const publicKey = naclUtil.encodeBase64(key.publicKey)\n const privateKey = naclUtil.encodeBase64(key.secretKey)\n\n return { publicKey, privateKey }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,IAAY,kBAAL,yBAAA,iBAAA;CACH,gBAAA,mBAAA;CACA,gBAAA,iBAAA;CACA,gBAAA,gBAAA;CACA,gBAAA,iBAAA;CACA,gBAAA,UAAA;;AACJ,EAAA,CAAA,CAAA;AAGA,MAAa,4BAA4BA,IAAAA,EAAE,OAAO;CAC9C,UAAUA,IAAAA,EAAE,WAAW,eAAe;CACtC,YAAYA,IAAAA,EAAE,OAAOA,IAAAA,EAAE,OAAO,GAAGA,IAAAA,EAAE,IAAI,CAAC,CAAC,CAAC,SAAS;AACvD,CAAC;AAGD,MAAa,sBAAsBA,IAAAA,EAAE,OAAO,EACxC,SAASA,IAAAA,EAAE,MAAM,yBAAyB,CAAC,CAAC,SAAS,EACzD,CAAC;;;ACGD,SAAS,gBAAgB,SAAkB;CACvC,OAAO;EACH,iBAAiB,QAAQ;EACzB,aAAa,QAAQ;EACrB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FDA,eAAAA,QAAS,aAAa,IAAI,SAEhB;CAAE;AACnC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Methods } from './rpc-gen/index.js';
|
|
|
3
3
|
import { Error as RpcError } from './rpc-gen/typings.js';
|
|
4
4
|
import { SigningProvider } from './config/schema.js';
|
|
5
5
|
export { SigningProvider };
|
|
6
|
-
export { default as buildController, Methods } from './rpc-gen/index.js';
|
|
6
|
+
export { default as buildController, type Methods } from './rpc-gen/index.js';
|
|
7
7
|
export * from './rpc-gen/typings.js';
|
|
8
8
|
export * from './SigningDriverStore.js';
|
|
9
9
|
export * from './config/schema.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAA;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAGxD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAGpD,OAAO,EAAE,eAAe,EAAE,CAAA;AAE1B,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAA;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAGxD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAGpD,OAAO,EAAE,eAAe,EAAE,CAAA;AAE1B,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,KAAK,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|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
properties: z.record(z.string(), z.any()).optional()
|
|
17
|
-
});
|
|
18
|
-
var signingConfigSchema = z.object({
|
|
19
|
-
drivers: z.array(signingDriverConfigSchema).optional()
|
|
1
|
+
import nacl from "tweetnacl";
|
|
2
|
+
import naclUtil from "tweetnacl-util";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
//#region src/config/schema.ts
|
|
5
|
+
let SigningProvider = /* @__PURE__ */ function(SigningProvider) {
|
|
6
|
+
SigningProvider["WALLET_KERNEL"] = "wallet-kernel";
|
|
7
|
+
SigningProvider["PARTICIPANT"] = "participant";
|
|
8
|
+
SigningProvider["FIREBLOCKS"] = "fireblocks";
|
|
9
|
+
SigningProvider["BLOCKDAEMON"] = "blockdaemon";
|
|
10
|
+
SigningProvider["DFNS"] = "dfns";
|
|
11
|
+
return SigningProvider;
|
|
12
|
+
}({});
|
|
13
|
+
const signingDriverConfigSchema = z.object({
|
|
14
|
+
provider: z.nativeEnum(SigningProvider),
|
|
15
|
+
properties: z.record(z.string(), z.any()).optional()
|
|
20
16
|
});
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
const signingConfigSchema = z.object({ drivers: z.array(signingDriverConfigSchema).optional() });
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/rpc-gen/index.ts
|
|
23
20
|
function buildController(methods) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
21
|
+
return {
|
|
22
|
+
signTransaction: methods.signTransaction,
|
|
23
|
+
signMessage: methods.signMessage,
|
|
24
|
+
getTransaction: methods.getTransaction,
|
|
25
|
+
getTransactions: methods.getTransactions,
|
|
26
|
+
getKeys: methods.getKeys,
|
|
27
|
+
createKey: methods.createKey,
|
|
28
|
+
getConfiguration: methods.getConfiguration,
|
|
29
|
+
setConfiguration: methods.setConfiguration,
|
|
30
|
+
subscribeTransactions: methods.subscribeTransactions
|
|
31
|
+
};
|
|
35
32
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
var CC_COIN_TYPE = 6767;
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/index.ts
|
|
35
|
+
const CC_COIN_TYPE = 6767;
|
|
40
36
|
function isRpcError(value) {
|
|
41
|
-
|
|
37
|
+
return value.error_description !== void 0;
|
|
42
38
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
naclUtil.decodeBase64(txHash),
|
|
51
|
-
naclUtil.decodeBase64(signature),
|
|
52
|
-
naclUtil.decodeBase64(publicKey)
|
|
53
|
-
);
|
|
39
|
+
let PartyMode = /* @__PURE__ */ function(PartyMode) {
|
|
40
|
+
PartyMode["INTERNAL"] = "internal";
|
|
41
|
+
PartyMode["EXTERNAL"] = "external";
|
|
42
|
+
return PartyMode;
|
|
43
|
+
}({});
|
|
44
|
+
const verifySignedTxHash = (txHash, publicKey, signature) => {
|
|
45
|
+
return nacl.sign.detached.verify(naclUtil.decodeBase64(txHash), naclUtil.decodeBase64(signature), naclUtil.decodeBase64(publicKey));
|
|
54
46
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
nacl.sign.detached(naclUtil.decodeBase64(txHash), decodedKey)
|
|
59
|
-
);
|
|
47
|
+
const signTransactionHash = (txHash, privateKey) => {
|
|
48
|
+
const decodedKey = naclUtil.decodeBase64(privateKey);
|
|
49
|
+
return naclUtil.encodeBase64(nacl.sign.detached(naclUtil.decodeBase64(txHash), decodedKey));
|
|
60
50
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
51
|
+
const signMessage = (message, privateKey) => {
|
|
52
|
+
const msgBytes = new TextEncoder().encode(message);
|
|
53
|
+
const decodedKey = naclUtil.decodeBase64(privateKey);
|
|
54
|
+
return naclUtil.encodeBase64(nacl.sign.detached(msgBytes, decodedKey));
|
|
65
55
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
56
|
+
const getPublicKeyFromPrivate = (privateKeyBase64) => {
|
|
57
|
+
const secretKey = naclUtil.decodeBase64(privateKeyBase64);
|
|
58
|
+
const keyPair = nacl.sign.keyPair.fromSecretKey(secretKey);
|
|
59
|
+
return naclUtil.encodeBase64(keyPair.publicKey);
|
|
70
60
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
61
|
+
const createKeyPair = () => {
|
|
62
|
+
const key = nacl.sign.keyPair();
|
|
63
|
+
return {
|
|
64
|
+
publicKey: naclUtil.encodeBase64(key.publicKey),
|
|
65
|
+
privateKey: naclUtil.encodeBase64(key.secretKey)
|
|
66
|
+
};
|
|
76
67
|
};
|
|
68
|
+
//#endregion
|
|
69
|
+
export { CC_COIN_TYPE, PartyMode, SigningProvider, buildController, createKeyPair, getPublicKeyFromPrivate, isRpcError, signMessage, signTransactionHash, signingConfigSchema, signingDriverConfigSchema, verifySignedTxHash };
|
|
77
70
|
|
|
78
|
-
export { CC_COIN_TYPE, PartyMode, SigningProvider, rpc_gen_default as buildController, createKeyPair, getPublicKeyFromPrivate, isRpcError, signMessage, signTransactionHash, signingConfigSchema, signingDriverConfigSchema, verifySignedTxHash };
|
|
79
|
-
//# sourceMappingURL=index.js.map
|
|
80
71
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/config/schema.ts","../src/rpc-gen/index.ts","../src/index.ts"],"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/config/schema.ts","../src/rpc-gen/index.ts","../src/index.ts"],"sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { z } from 'zod'\n\nexport enum SigningProvider {\n WALLET_KERNEL = 'wallet-kernel',\n PARTICIPANT = 'participant',\n FIREBLOCKS = 'fireblocks',\n BLOCKDAEMON = 'blockdaemon',\n DFNS = 'dfns',\n}\n\n// Generic signing driver configuration schema\nexport const signingDriverConfigSchema = z.object({\n provider: z.nativeEnum(SigningProvider),\n properties: z.record(z.string(), z.any()).optional(),\n})\n\n// Top-level Signing Configuration Schema - array of driver configs\nexport const signingConfigSchema = z.object({\n drivers: z.array(signingDriverConfigSchema).optional(),\n})\n\n// Type exports\nexport type SigningDriverAppConfig = z.infer<typeof signingDriverConfigSchema>\nexport type SigningConfig = z.infer<typeof signingConfigSchema>\n","// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { SignTransaction } from './typings.js'\nimport { SignMessage } from './typings.js'\nimport { GetTransaction } from './typings.js'\nimport { GetTransactions } from './typings.js'\nimport { GetKeys } from './typings.js'\nimport { CreateKey } from './typings.js'\nimport { GetConfiguration } from './typings.js'\nimport { SetConfiguration } from './typings.js'\nimport { SubscribeTransactions } from './typings.js'\n\nexport type Methods = {\n signTransaction: SignTransaction\n signMessage: SignMessage\n getTransaction: GetTransaction\n getTransactions: GetTransactions\n getKeys: GetKeys\n createKey: CreateKey\n getConfiguration: GetConfiguration\n setConfiguration: SetConfiguration\n subscribeTransactions: SubscribeTransactions\n}\n\nfunction buildController(methods: Methods) {\n return {\n signTransaction: methods.signTransaction,\n signMessage: methods.signMessage,\n getTransaction: methods.getTransaction,\n getTransactions: methods.getTransactions,\n getKeys: methods.getKeys,\n createKey: methods.createKey,\n getConfiguration: methods.getConfiguration,\n setConfiguration: methods.setConfiguration,\n subscribeTransactions: methods.subscribeTransactions,\n }\n}\n\nexport default buildController\n","// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { AuthContext } from '@canton-network/core-wallet-auth'\nimport { Methods } from './rpc-gen/index.js'\nimport { Error as RpcError } from './rpc-gen/typings.js'\nimport nacl from 'tweetnacl'\nimport naclUtil from 'tweetnacl-util'\nimport { SigningProvider } from './config/schema.js'\n\n// Re-export SigningProvider from config schema\nexport { SigningProvider }\n\nexport { default as buildController, type Methods } from './rpc-gen/index.js'\nexport * from './rpc-gen/typings.js'\nexport * from './SigningDriverStore.js'\nexport * from './config/schema.js'\n\nexport const CC_COIN_TYPE = 6767\n\nexport function isRpcError<T>(value: T | RpcError): value is RpcError {\n return (value as RpcError).error_description !== undefined\n}\n\nexport enum PartyMode {\n INTERNAL = 'internal',\n EXTERNAL = 'external',\n}\n\nexport type PublicKey = string\nexport type PrivateKey = string\n\nexport interface KeyPair {\n publicKey: PublicKey\n privateKey: PrivateKey\n}\n\nexport interface SigningDriverInterface {\n partyMode: PartyMode\n signingProvider: SigningProvider\n controller: (userId: AuthContext['userId'] | undefined) => Methods\n}\n\nexport const verifySignedTxHash = (\n txHash: string,\n publicKey: string,\n signature: string\n): boolean => {\n return nacl.sign.detached.verify(\n naclUtil.decodeBase64(txHash),\n naclUtil.decodeBase64(signature),\n naclUtil.decodeBase64(publicKey)\n )\n}\n\nexport const signTransactionHash = (\n txHash: string,\n privateKey: string\n): string => {\n const decodedKey = naclUtil.decodeBase64(privateKey)\n\n return naclUtil.encodeBase64(\n nacl.sign.detached(naclUtil.decodeBase64(txHash), decodedKey)\n )\n}\n\nexport const signMessage = (message: string, privateKey: string): string => {\n const msgBytes = new TextEncoder().encode(message)\n const decodedKey = naclUtil.decodeBase64(privateKey)\n return naclUtil.encodeBase64(nacl.sign.detached(msgBytes, decodedKey))\n}\n\nexport const getPublicKeyFromPrivate = (privateKeyBase64: string): string => {\n const secretKey = naclUtil.decodeBase64(privateKeyBase64)\n const keyPair = nacl.sign.keyPair.fromSecretKey(secretKey)\n return naclUtil.encodeBase64(keyPair.publicKey)\n}\n\nexport const createKeyPair = (): KeyPair => {\n const key = nacl.sign.keyPair()\n const publicKey = naclUtil.encodeBase64(key.publicKey)\n const privateKey = naclUtil.encodeBase64(key.secretKey)\n\n return { publicKey, privateKey }\n}\n"],"mappings":";;;;AAKA,IAAY,kBAAL,yBAAA,iBAAA;CACH,gBAAA,mBAAA;CACA,gBAAA,iBAAA;CACA,gBAAA,gBAAA;CACA,gBAAA,iBAAA;CACA,gBAAA,UAAA;;AACJ,EAAA,CAAA,CAAA;AAGA,MAAa,4BAA4B,EAAE,OAAO;CAC9C,UAAU,EAAE,WAAW,eAAe;CACtC,YAAY,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,SAAS;AACvD,CAAC;AAGD,MAAa,sBAAsB,EAAE,OAAO,EACxC,SAAS,EAAE,MAAM,yBAAyB,CAAC,CAAC,SAAS,EACzD,CAAC;;;ACGD,SAAS,gBAAgB,SAAkB;CACvC,OAAO;EACH,iBAAiB,QAAQ;EACzB,aAAa,QAAQ;EACrB,gBAAgB,QAAQ;EACxB,iBAAiB,QAAQ;EACzB,SAAS,QAAQ;EACjB,WAAW,QAAQ;EACnB,kBAAkB,QAAQ;EAC1B,kBAAkB,QAAQ;EAC1B,uBAAuB,QAAQ;CACnC;AACJ;;;ACnBA,MAAa,eAAe;AAE5B,SAAgB,WAAc,OAAwC;CAClE,OAAQ,MAAmB,sBAAsB,KAAA;AACrD;AAEA,IAAY,YAAL,yBAAA,WAAA;CACH,UAAA,cAAA;CACA,UAAA,cAAA;;AACJ,EAAA,CAAA,CAAA;AAgBA,MAAa,sBACT,QACA,WACA,cACU;CACV,OAAO,KAAK,KAAK,SAAS,OACtB,SAAS,aAAa,MAAM,GAC5B,SAAS,aAAa,SAAS,GAC/B,SAAS,aAAa,SAAS,CACnC;AACJ;AAEA,MAAa,uBACT,QACA,eACS;CACT,MAAM,aAAa,SAAS,aAAa,UAAU;CAEnD,OAAO,SAAS,aACZ,KAAK,KAAK,SAAS,SAAS,aAAa,MAAM,GAAG,UAAU,CAChE;AACJ;AAEA,MAAa,eAAe,SAAiB,eAA+B;CACxE,MAAM,WAAW,IAAI,YAAY,CAAC,CAAC,OAAO,OAAO;CACjD,MAAM,aAAa,SAAS,aAAa,UAAU;CACnD,OAAO,SAAS,aAAa,KAAK,KAAK,SAAS,UAAU,UAAU,CAAC;AACzE;AAEA,MAAa,2BAA2B,qBAAqC;CACzE,MAAM,YAAY,SAAS,aAAa,gBAAgB;CACxD,MAAM,UAAU,KAAK,KAAK,QAAQ,cAAc,SAAS;CACzD,OAAO,SAAS,aAAa,QAAQ,SAAS;AAClD;AAEA,MAAa,sBAA+B;CACxC,MAAM,MAAM,KAAK,KAAK,QAAQ;CAI9B,OAAO;EAAE,WAHS,SAAS,aAAa,IAAI,SAG3B;EAAG,YAFD,SAAS,aAAa,IAAI,SAEhB;CAAE;AACnC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canton-network/core-signing-lib",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Core library for signing driver implementations",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -16,16 +16,16 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "
|
|
20
|
-
"dev": "
|
|
19
|
+
"build": "tsdown --onSuccess \"tsc\"",
|
|
20
|
+
"dev": "tsdown --watch --onSuccess \"tsc\"",
|
|
21
21
|
"flatpack": "yarn pack --out \"$FLATPACK_OUTDIR\"",
|
|
22
22
|
"clean": "tsc -b --clean && rm -rf ./dist",
|
|
23
23
|
"test": "vitest run --project node",
|
|
24
24
|
"test:coverage": "vitest run --project node --coverage"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@canton-network/core-wallet-auth": "^1.
|
|
28
|
-
"fs-extra": "^11.3.
|
|
27
|
+
"@canton-network/core-wallet-auth": "^1.9.0",
|
|
28
|
+
"fs-extra": "^11.3.6",
|
|
29
29
|
"lodash": "^4.18.1",
|
|
30
30
|
"tweetnacl": "^1.0.3",
|
|
31
31
|
"tweetnacl-util": "^0.15.1",
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/fs-extra": "^11.0.4",
|
|
36
36
|
"@types/lodash": "^4.17.24",
|
|
37
|
-
"@types/node": "^25.9.
|
|
38
|
-
"@vitest/coverage-v8": "^4.1.
|
|
39
|
-
"
|
|
37
|
+
"@types/node": "^25.9.4",
|
|
38
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
39
|
+
"tsdown": "^0.22.9",
|
|
40
40
|
"typescript": "^5.9.3",
|
|
41
|
-
"vitest": "^4.1.
|
|
41
|
+
"vitest": "^4.1.10"
|
|
42
42
|
},
|
|
43
43
|
"files": [
|
|
44
44
|
"dist/**"
|