|
1 | 1 | import { VcFlowRequestWire } from "@dfinity/internet-identity-vc-api"; |
2 | | - |
3 | | -import type { Identity, SignIdentity } from "@dfinity/agent"; |
4 | | -import { Actor, HttpAgent } from "@dfinity/agent"; |
| 2 | +import { bytesToHex } from "@noble/hashes/utils"; |
| 3 | +import type { Identity, SignIdentity } from "@icp-sdk/core/agent"; |
| 4 | +import { Actor, HttpAgent } from "@icp-sdk/core/agent"; |
5 | 5 | import { |
6 | 6 | DelegationChain, |
7 | 7 | DelegationIdentity, |
8 | 8 | Ed25519KeyIdentity, |
9 | | -} from "@dfinity/identity"; |
10 | | -import { Principal } from "@dfinity/principal"; |
| 9 | +} from "@icp-sdk/core/identity"; |
| 10 | +import { Principal } from "@icp-sdk/core/principal"; |
11 | 11 |
|
12 | 12 | import React, { useState } from "react"; |
13 | 13 | import ReactDOM from "react-dom/client"; |
@@ -134,11 +134,38 @@ const updateDelegationView = ({ |
134 | 134 | } |
135 | 135 |
|
136 | 136 | if (identity instanceof DelegationIdentity) { |
137 | | - delegationEl.innerText = JSON.stringify( |
138 | | - identity.getDelegation().toJSON(), |
139 | | - undefined, |
140 | | - 2, |
141 | | - ); |
| 137 | + const delegation = identity.getDelegation(); |
| 138 | + let jsonResult; |
| 139 | + try { |
| 140 | + // `toJSON` is failing due to `bytesToHex(delegation.publicKey)` |
| 141 | + // `bytesToHex` expects a Uint8Array and delegation.publicKey is a ArrayBuffer |
| 142 | + // jsonResult = delegation.toJSON(); |
| 143 | + jsonResult = { |
| 144 | + delegations: delegation.delegations.map((signedDelegation) => { |
| 145 | + const { delegation, signature } = signedDelegation; |
| 146 | + const { targets } = delegation; |
| 147 | + return { |
| 148 | + delegation: { |
| 149 | + expiration: delegation.expiration.toString(16), |
| 150 | + pubkey: bytesToHex(delegation.pubkey), |
| 151 | + ...(targets && { |
| 152 | + targets: targets.map((t) => t.toHex()), |
| 153 | + }), |
| 154 | + }, |
| 155 | + signature: bytesToHex(new Uint8Array(signature)), |
| 156 | + }; |
| 157 | + }), |
| 158 | + publicKey: bytesToHex(new Uint8Array(delegation.publicKey)), |
| 159 | + }; |
| 160 | + } catch (error) { |
| 161 | + console.error("toJSON error:", error); |
| 162 | + jsonResult = { |
| 163 | + error: "toJSON failed", |
| 164 | + message: error instanceof Error ? error.message : String(error), |
| 165 | + }; |
| 166 | + } |
| 167 | + |
| 168 | + delegationEl.innerText = JSON.stringify(jsonResult, undefined, 2); |
142 | 169 |
|
143 | 170 | // cannot use Math.min, as we deal with bigint here |
144 | 171 | const nextExpiration = identity |
@@ -219,7 +246,7 @@ const readCanisterId = (): string => { |
219 | 246 | const init = async () => { |
220 | 247 | signInBtn.onclick = async () => { |
221 | 248 | const maxTimeToLive_ = BigInt(maxTimeToLiveEl.value); |
222 | | - // The default max TTL setin the @dfinity/auth-client library |
| 249 | + // The default max TTL set in the @icp-sdk/auth/client library |
223 | 250 | const authClientDefaultMaxTTL = |
224 | 251 | /* hours */ BigInt(8) * /* nanoseconds */ BigInt(3_600_000_000_000); |
225 | 252 | const maxTimeToLive = |
|
0 commit comments