You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: motoko/threshold-schnorr/README.md
+127-46
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
We present a minimal example canister smart contract for showcasing the [threshold Schnorr](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-sign_with_schnorr) API.
4
4
5
5
The example canister is a signing oracle that creates Schnorr signatures with
6
-
keys derived based on the canister ID and the chosen algorithm, either BIP340 or
6
+
keys derived based on the canister ID and the chosen algorithm, either BIP340/BIP341 or
7
7
Ed25519.
8
8
9
9
More specifically:
@@ -27,6 +27,7 @@ This example requires an installation of:
27
27
28
28
-[x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install).
29
29
-[x] Clone the example dapp project: `git clone https://github.com/dfinity/examples`
30
+
-[x] For running tests also install [`npm`](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm).
30
31
31
32
Begin by opening a terminal window.
32
33
@@ -64,37 +65,71 @@ If you open the URL in a web browser, you will see a web UI that shows the
64
65
public methods the canister exposes. Since the canister exposes `public_key`,
65
66
`sign`, and `verify`, those are rendered in the web UI.
66
67
68
+
### Step 3 (optional): Run tests
69
+
70
+
```bash
71
+
npm install
72
+
make test
73
+
```
74
+
75
+
#### What this does
76
+
77
+
-`npm install` installs test javascript dependencies
78
+
-`make test` deploys and tests the canister code on the local version of the
79
+
IC, and also makes the canister call a mock canister for Schnorr API instead
80
+
of the management canister
81
+
82
+
67
83
## Deploying the canister on the mainnet
68
84
69
-
To deploy this canister the mainnet, one needs to do two things:
85
+
To deploy this canister on the mainnet, one needs to do two things:
70
86
71
87
- Acquire cycles (equivalent of "gas" in other blockchains). This is necessary for all canisters.
72
88
- Update the sample source code to have the right key ID. This is unique to this canister.
73
89
74
90
### Acquire cycles to deploy
75
91
76
-
Deploying to the Internet Computer requires [cycles](https://internetcomputer.org/docs/current/developer-docs/getting-started/tokens-and-cycles) (the equivalent of "gas" on other blockchains).
can be installed and used instead of the management canister. Note also that the
102
+
chain-key testing canister is deployed on the mainnet and can be used for mainnet
103
+
testing to reduce the costs, see the linked repo for more details.
104
+
105
+
This sample canister allows the caller to change the management canister address
106
+
for Schnorr by calling the `for_test_only_change_management_canister_id`
107
+
endpoint with the target canister principal. With `dfx`, this can be done
108
+
automatically with `make mock`, which will install the chain-key testing canister
109
+
and use it instead of the management canister. Note that `dfx` should be running
110
+
to successfully run `make mock`.
77
111
78
112
### Update source code with the right key ID
79
113
80
114
To deploy the sample code, the canister needs the right key ID for the right environment. Specifically, one needs to replace the value of the `key_id` in the `src/schnorr_example_motoko/src/lib.rs` file of the sample code. Before deploying to mainnet, one should modify the code to use the right name of the `key_id`.
81
115
82
-
There are three options that are planed to be supported:
116
+
There are four options that are supported:
83
117
118
+
*`insecure_test_key_1`: the key ID supported by the `chainkey_testing_canister`
*`dfx_test_key`: a default key ID that is used in deploying to a local version of IC (via IC SDK).
85
121
*`test_key_1`: a master **test** key ID that is used in mainnet.
86
122
*`key_1`: a master **production** key ID that is used in mainnet.
87
123
88
124
For example, the default code in `src/schnorr_example_motoko/src/main.mo`
89
-
hard-codes the used of `dfx_test_key` and derives the key ID as follows and can
125
+
hard-codes the use of `insecure_test_key_1` and derives the key ID as follows and can
90
126
be deployed locally:
91
127
92
-
93
128
```motoko
94
-
key_id = { algorithm = algorithm_arg; name = "dfx_test_key" }
129
+
key_id = { algorithm = algorithm_arg; name = "insecure_test_key_1" }
95
130
```
96
131
97
-
IMPORTANT: To deploy to IC mainnet, one needs to replace `"dfx_test_key"` with
132
+
IMPORTANT: To deploy to IC mainnet, one needs to replace `"insecure_test_key_1"` with
98
133
either `"test_key_1"` or `"key_1"` depending on the desired intent. Both uses of
99
134
key ID in `src/schnorr_example_motoko/src/main.mo` must be consistent.
100
135
@@ -124,7 +159,7 @@ mainnet.
124
159
125
160
### Using the Candid UI
126
161
127
-
If you deployed your canister locally or to the mainnet, you should have a URL to the Candid web UI where you can access the public methods. We can call the `public-key` method.
162
+
If you deployed your canister locally or to the mainnet, you should have a URL to the Candid web UI where you can access the public methods. We can call the `public_key` method.
128
163
129
164
In the example below, the method returns
130
165
`6e48e755842d0323be83edc7fc8766a20423c8127f7731993873d2f123d01a34` as the
@@ -141,23 +176,23 @@ Ed25519 public key.
141
176
142
177
143
178
### Code walkthrough
144
-
Open the file `lib.rs`, which will show the following Motoko code that
179
+
Open the file `main.mo`, which will show the following Motoko code that
@@ -187,20 +222,28 @@ For obtaining the canister's root public key, the derivation path in the API can
187
222
Computing threshold Schnorr signatures is the core functionality of this feature. **Canisters do not hold Schnorr keys themselves**, but keys are derived from a master key held by dedicated subnets. A canister can request the computation of a signature through the management canister API. The request is then routed to a subnet holding the specified key and the subnet computes the requested signature using threshold cryptography. Thereby, it derives the canister root key or a key obtained through further derivation, as part of the signature protocol, from a shared secret and the requesting canister's principal identifier. Thus, a canister can only request signatures to be created for its canister root key or a key derived from it. This means, that canisters "control" their private Schnorr keys in that they decide when signatures are to be created with them, but don't hold a private key themselves.
0 commit comments