Skip to content

Commit 6da07bc

Browse files
committed
fix: actions
1 parent 20a6219 commit 6da07bc

File tree

6 files changed

+220
-211
lines changed

6 files changed

+220
-211
lines changed

infrastructure/eid-wallet/src/routes/(app)/scan-qr/+page.svelte

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,17 @@ import {
88
QrCodeIcon,
99
} from "@hugeicons/core-free-icons";
1010
import { HugeiconsIcon } from "@hugeicons/svelte";
11+
import {
12+
Format,
13+
type PermissionState,
14+
type Scanned,
15+
cancel,
16+
checkPermissions,
17+
requestPermissions,
18+
scan,
19+
} from "@tauri-apps/plugin-barcode-scanner";
20+
import { onDestroy, onMount } from "svelte";
1121
import type { SVGAttributes } from "svelte/elements";
12-
import { scan, cancel, Format, checkPermissions, requestPermissions, type PermissionState, type Scanned } from '@tauri-apps/plugin-barcode-scanner';
13-
import { onDestroy, onMount } from "svelte";
1422
1523
const pathProps: SVGAttributes<SVGPathElement> = {
1624
stroke: "white",
@@ -23,64 +31,63 @@ let codeScannedDrawerOpen = $state(false);
2331
let loggedInDrawerOpen = $state(false);
2432
let flashlightOn = $state(false);
2533
26-
let scannedData: Scanned | undefined = $state(undefined)
34+
let scannedData: Scanned | undefined = $state(undefined);
2735
2836
let scanning = false;
2937
let loading = false;
3038
3139
let permissions_nullable: PermissionState | null;
3240
33-
async function startScan() {
41+
async function startScan() {
3442
let permissions = await checkPermissions()
35-
.then((permissions) => {
36-
return permissions;
37-
})
38-
.catch(() => {
39-
return null; // possibly return "denied"? or does that imply that the check has been successful, but was actively denied?
40-
});
43+
.then((permissions) => {
44+
return permissions;
45+
})
46+
.catch(() => {
47+
return null; // possibly return "denied"? or does that imply that the check has been successful, but was actively denied?
48+
});
4149
4250
// TODO: handle receiving "prompt-with-rationale" (issue: https://github.com/tauri-apps/plugins-workspace/issues/979)
43-
if (permissions === 'prompt') {
44-
permissions = await requestPermissions(); // handle in more detail?
51+
if (permissions === "prompt") {
52+
permissions = await requestPermissions(); // handle in more detail?
4553
}
4654
4755
permissions_nullable = permissions;
4856
49-
if (permissions === 'granted') {
50-
// Scanning parameters
51-
const formats = [Format.QRCode];
52-
const windowed = true;
53-
54-
scanning = true;
55-
scan({ formats, windowed })
56-
.then((res) => {
57-
console.log("Scan result:", res);
58-
scannedData = res;
59-
codeScannedDrawerOpen = true;
60-
})
61-
.catch((error) => {
62-
// TODO: display error to user
63-
console.error("Scan error:", error);
64-
})
65-
.finally(() => {
66-
scanning = false;
67-
});
57+
if (permissions === "granted") {
58+
// Scanning parameters
59+
const formats = [Format.QRCode];
60+
const windowed = true;
61+
62+
scanning = true;
63+
scan({ formats, windowed })
64+
.then((res) => {
65+
console.log("Scan result:", res);
66+
scannedData = res;
67+
codeScannedDrawerOpen = true;
68+
})
69+
.catch((error) => {
70+
// TODO: display error to user
71+
console.error("Scan error:", error);
72+
})
73+
.finally(() => {
74+
scanning = false;
75+
});
6876
}
69-
}
77+
}
7078
71-
async function cancelScan() {
79+
async function cancelScan() {
7280
await cancel();
7381
scanning = false;
74-
}
75-
82+
}
7683
7784
onMount(async () => {
7885
startScan();
79-
})
86+
});
8087
81-
onDestroy(async() => {
88+
onDestroy(async () => {
8289
await cancelScan();
83-
})
90+
});
8491
</script>
8592

8693
<AppNav title="Scan QR Code" titleClasses="text-white" iconColor="white" />

infrastructure/w3id/src/index.ts

Lines changed: 118 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -7,134 +7,136 @@ import { generateRandomAlphaNum } from "./utils/rand";
77
import { generateUuid } from "./utils/uuid";
88

99
export class W3ID {
10-
constructor(
11-
public id: string,
12-
public logs?: IDLogManager,
13-
) {}
10+
constructor(
11+
public id: string,
12+
public logs?: IDLogManager,
13+
) {}
1414

15-
/**
16-
* Signs a JWT with the W3ID's signer
17-
* @param payload - The JWT payload
18-
* @param header - Optional JWT header (defaults to using the signer's alg and W3ID's id as kid)
19-
* @returns The signed JWT
20-
*/
21-
public async signJWT(
22-
payload: JWTPayload,
23-
header?: JWTHeader,
24-
): Promise<string> {
25-
if (!this.logs?.signer) {
26-
throw new Error("W3ID must have a signer to sign JWTs");
27-
}
28-
return signJWT(this.logs.signer, payload, `@${this.id}#0`, header);
29-
}
15+
/**
16+
* Signs a JWT with the W3ID's signer
17+
* @param payload - The JWT payload
18+
* @param header - Optional JWT header (defaults to using the signer's alg and W3ID's id as kid)
19+
* @returns The signed JWT
20+
*/
21+
public async signJWT(
22+
payload: JWTPayload,
23+
header?: JWTHeader,
24+
): Promise<string> {
25+
if (!this.logs?.signer) {
26+
throw new Error("W3ID must have a signer to sign JWTs");
27+
}
28+
return signJWT(this.logs.signer, payload, `@${this.id}#0`, header);
29+
}
3030
}
3131

3232
export class W3IDBuilder {
33-
private signer?: Signer;
34-
private repository?: StorageSpec<LogEvent, LogEvent>;
35-
private entropy?: string;
36-
private namespace?: string;
37-
private nextKeyHash?: string;
38-
private global?: boolean = false;
33+
private signer?: Signer;
34+
private repository?: StorageSpec<LogEvent, LogEvent>;
35+
private entropy?: string;
36+
private namespace?: string;
37+
private nextKeyHash?: string;
38+
private global?: boolean = false;
3939

40-
/**
41-
* Specify entropy to create the identity with
42-
*
43-
* @param {string} str
44-
*/
45-
public withEntropy(str: string): W3IDBuilder {
46-
this.entropy = str;
47-
return this;
48-
}
40+
/**
41+
* Specify entropy to create the identity with
42+
*
43+
* @param {string} str
44+
*/
45+
public withEntropy(str: string): W3IDBuilder {
46+
this.entropy = str;
47+
return this;
48+
}
4949

50-
/**
51-
* Specify namespace to use to generate the UUIDv5
52-
*
53-
* @param {string} uuid
54-
*/
55-
public withNamespace(uuid: string): W3IDBuilder {
56-
this.namespace = uuid;
57-
return this;
58-
}
50+
/**
51+
* Specify namespace to use to generate the UUIDv5
52+
*
53+
* @param {string} uuid
54+
*/
55+
public withNamespace(uuid: string): W3IDBuilder {
56+
this.namespace = uuid;
57+
return this;
58+
}
5959

60-
/**
61-
* Specify whether to create a global identifier or a local identifer
62-
*
63-
* According to the project specification there are supposed to be 2 main types of
64-
* W3ID's ones which are tied to more permanent entities
65-
*
66-
* A global identifer is expected to live at the registry and starts with an \`@\`
67-
*
68-
* @param {boolean} isGlobal
69-
*/
70-
public withGlobal(isGlobal: boolean): W3IDBuilder {
71-
this.global = isGlobal;
72-
return this;
73-
}
60+
/**
61+
* Specify whether to create a global identifier or a local identifer
62+
*
63+
* According to the project specification there are supposed to be 2 main types of
64+
* W3ID's ones which are tied to more permanent entities
65+
*
66+
* A global identifer is expected to live at the registry and starts with an \`@\`
67+
*
68+
* @param {boolean} isGlobal
69+
*/
70+
public withGlobal(isGlobal: boolean): W3IDBuilder {
71+
this.global = isGlobal;
72+
return this;
73+
}
7474

75-
/**
76-
* Add a logs repository to the W3ID, a rotateble key attached W3ID would need a
77-
* repository in which the logs would be stored
78-
*
79-
* @param {StorageSpec<LogEvent, LogEvent>} storage
80-
*/
81-
public withRepository(storage: StorageSpec<LogEvent, LogEvent>): W3IDBuilder {
82-
this.repository = storage;
83-
return this;
84-
}
75+
/**
76+
* Add a logs repository to the W3ID, a rotateble key attached W3ID would need a
77+
* repository in which the logs would be stored
78+
*
79+
* @param {StorageSpec<LogEvent, LogEvent>} storage
80+
*/
81+
public withRepository(
82+
storage: StorageSpec<LogEvent, LogEvent>,
83+
): W3IDBuilder {
84+
this.repository = storage;
85+
return this;
86+
}
8587

86-
/**
87-
* Attach a keypair to the W3ID, a key attached W3ID would also need a repository
88-
* to be added.
89-
*
90-
* @param {Signer} signer
91-
*/
92-
public withSigner(signer: Signer): W3IDBuilder {
93-
this.signer = signer;
94-
return this;
95-
}
88+
/**
89+
* Attach a keypair to the W3ID, a key attached W3ID would also need a repository
90+
* to be added.
91+
*
92+
* @param {Signer} signer
93+
*/
94+
public withSigner(signer: Signer): W3IDBuilder {
95+
this.signer = signer;
96+
return this;
97+
}
9698

97-
/**
98-
* Specify the SHA256 hash of the next key which will sign the next log entry after
99-
* rotation of keys
100-
*
101-
* @param {string} hash
102-
*/
103-
public withNextKeyHash(hash: string): W3IDBuilder {
104-
this.nextKeyHash = hash;
105-
return this;
106-
}
99+
/**
100+
* Specify the SHA256 hash of the next key which will sign the next log entry after
101+
* rotation of keys
102+
*
103+
* @param {string} hash
104+
*/
105+
public withNextKeyHash(hash: string): W3IDBuilder {
106+
this.nextKeyHash = hash;
107+
return this;
108+
}
107109

108-
/**
109-
* Build the W3ID with provided builder options
110-
*
111-
* @returns Promise<W3ID>
112-
*/
113-
public async build(): Promise<W3ID> {
114-
this.entropy = this.entropy ?? generateRandomAlphaNum();
115-
this.namespace = this.namespace ?? uuidv4();
116-
const id = `${
117-
this.global ? "@" : ""
118-
}${generateUuid(this.entropy, this.namespace)}`;
119-
if (!this.signer) {
120-
return new W3ID(id);
121-
}
122-
if (!this.repository)
123-
throw new Error(
124-
"Repository is required, pass with `withRepository` method",
125-
);
110+
/**
111+
* Build the W3ID with provided builder options
112+
*
113+
* @returns Promise<W3ID>
114+
*/
115+
public async build(): Promise<W3ID> {
116+
this.entropy = this.entropy ?? generateRandomAlphaNum();
117+
this.namespace = this.namespace ?? uuidv4();
118+
const id = `${
119+
this.global ? "@" : ""
120+
}${generateUuid(this.entropy, this.namespace)}`;
121+
if (!this.signer) {
122+
return new W3ID(id);
123+
}
124+
if (!this.repository)
125+
throw new Error(
126+
"Repository is required, pass with `withRepository` method",
127+
);
126128

127-
if (!this.nextKeyHash)
128-
throw new Error(
129-
"NextKeyHash is required pass with `withNextKeyHash` method",
130-
);
131-
const logs = new IDLogManager(this.repository, this.signer);
132-
await logs.createLogEvent({
133-
id,
134-
nextKeyHashes: [this.nextKeyHash],
135-
});
136-
return new W3ID(id, logs);
137-
}
129+
if (!this.nextKeyHash)
130+
throw new Error(
131+
"NextKeyHash is required pass with `withNextKeyHash` method",
132+
);
133+
const logs = new IDLogManager(this.repository, this.signer);
134+
await logs.createLogEvent({
135+
id,
136+
nextKeyHashes: [this.nextKeyHash],
137+
});
138+
return new W3ID(id, logs);
139+
}
138140
}
139141

140142
export * from "./utils/jwt";

0 commit comments

Comments
 (0)