Skip to content

Commit dba38d1

Browse files
authored
Fix ICRC-29 heartbeat in Safari (dfinity#3620)
Fix ICRC-29 heartbeat in Safari and remove signer-js deps from II. # Changes - Move `HeartbeatServer` implementation from signer-js into II. - Add `"wake-up-client"` message workaround for Safari to it's implementation. - Remove other usages of signer-js so the dependency can be removed from II. - Update test-app to latest signer-js version. # Tests Manually verified that direct OpenID flow now works as expected in Safari.
1 parent 2d5680a commit dba38d1

9 files changed

Lines changed: 281 additions & 96 deletions

File tree

demos/test-app/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"private": true,
55
"dependencies": {
66
"@icp-sdk/core": "*",
7-
"@slide-computer/signer": "*",
8-
"@slide-computer/signer-web": "*",
7+
"@slide-computer/signer": "^4.2.0",
8+
"@slide-computer/signer-web": "^4.2.0",
99
"@noble/hashes": "*",
1010
"buffer": "^6.0.3",
1111
"jose": "^5.1.2",
@@ -21,6 +21,7 @@
2121
"devDependencies": {
2222
"@dfinity/internet-identity-vc-api": "*",
2323
"@dfinity/internet-identity-vite-plugins": "*",
24+
"@icp-sdk/core": "^4.2.3",
2425
"@types/react": "^18.2.38",
2526
"@types/react-dom": "^18.2.17",
2627
"@vitejs/plugin-react": "^4.2.0",

demos/test-app/src/auth.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
SignedDelegation,
77
} from "@icp-sdk/core/identity";
88
import { Principal } from "@icp-sdk/core/principal";
9-
import { fromBase64, Signer } from "@slide-computer/signer";
9+
import { Signer } from "@slide-computer/signer";
1010
import { PostMessageTransport } from "@slide-computer/signer-web";
1111

1212
// The type of response from II as per the spec
@@ -85,8 +85,10 @@ export const authWithII = async ({
8585
[
8686
key,
8787
{
88-
value: new Uint8Array(fromBase64(value)),
89-
signature: new Uint8Array(fromBase64(signature)),
88+
// @ts-ignore Not known in TS types yet but supported in all browsers
89+
value: Uint8Array.fromBase64(value),
90+
// @ts-ignore Not known in TS types yet but supported in all browsers
91+
signature: Uint8Array.fromBase64(signature),
9092
expiration: BigInt(expiration),
9193
},
9294
] as [string, CertifiedAttribute],
@@ -96,7 +98,7 @@ export const authWithII = async ({
9698
: Promise.resolve({});
9799
const delegationPromise = signer.delegation({
98100
maxTimeToLive,
99-
publicKey: new Uint8Array(sessionIdentity.getPublicKey().toDer()).buffer,
101+
publicKey: new Uint8Array(sessionIdentity.getPublicKey().toDer()),
100102
});
101103
const [delegation, certifiedAttributes] = await Promise.all([
102104
delegationPromise,

demos/test-app/src/index.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,10 @@ const init = async () => {
397397

398398
updateAlternativeOriginsBtn.onclick = async () => {
399399
const canisterId = Principal.fromText(readCanisterId());
400-
const httpAgent = new HttpAgent({ host: hostUrlEl.value });
401-
await httpAgent.fetchRootKey();
400+
const httpAgent = await HttpAgent.create({
401+
host: hostUrlEl.value,
402+
shouldFetchRootKey: true,
403+
});
402404
const actor = Actor.createActor(idlFactory, {
403405
agent: httpAgent,
404406
canisterId,
@@ -430,11 +432,11 @@ window.addEventListener("DOMContentLoaded", init);
430432

431433
whoamiBtn.addEventListener("click", async () => {
432434
const canisterId = Principal.fromText(readCanisterId());
433-
const agent = new HttpAgent({
435+
const agent = await HttpAgent.create({
434436
host: hostUrlEl.value,
435437
identity: delegationIdentity,
438+
shouldFetchRootKey: true,
436439
});
437-
await agent.fetchRootKey();
438440
const actor = Actor.createActor(idlFactory, {
439441
agent,
440442
canisterId,

package-lock.json

Lines changed: 87 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@
9595
"@lingui/core": "^5.5.1",
9696
"@lucide/svelte": "^0.553.0",
9797
"@noble/hashes": "^1.8.0",
98-
"@slide-computer/signer": "^4.0.0",
99-
"@slide-computer/signer-web": "^4.0.0",
10098
"bip39": "^3.0.4",
10199
"borc": "^2.1.1",
102100
"buffer": "^6.0.3",
@@ -124,4 +122,4 @@
124122
"src/vite-plugins",
125123
"src/sig-verifier-js"
126124
]
127-
}
125+
}

src/frontend/src/lib/stores/channelStore.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import type {
88
} from "$lib/utils/transport/utils";
99
import { PostMessageTransport } from "$lib/utils/transport/postMessage";
1010
import { LegacyTransport } from "$lib/utils/transport/legacy";
11-
import type {
12-
PermissionScope,
13-
SupportedStandard,
14-
} from "@slide-computer/signer";
1511
import { canisterConfig, getPrimaryOrigin } from "$lib/globals";
1612

1713
type ChannelStore = Readable<Channel | undefined> & {
@@ -34,7 +30,7 @@ const getTransports = (): Transport[] => {
3430
];
3531
};
3632

37-
const supportedStandards: SupportedStandard[] = [
33+
const supportedStandards = [
3834
{
3935
name: "ICRC-25",
4036
url: "https://github.com/dfinity/wg-identity-authentication/blob/main/topics/icrc_25_signer_interaction_standard.md",
@@ -52,7 +48,7 @@ const supportedStandards: SupportedStandard[] = [
5248
url: "https://github.com/dfinity/wg-identity-authentication/blob/main/topics/icrc_95_derivationorigin.md",
5349
},
5450
];
55-
const scopes: PermissionScope[] = [
51+
const scopes = [
5652
{
5753
method: "icrc34_delegation",
5854
},

0 commit comments

Comments
 (0)