Skip to content

Commit 55492f3

Browse files
authored
v1 Release
* Fixed configuration order of operations & updated version * Added build instructions to README * Bumped deps * Formatting fixes
1 parent b43de1e commit 55492f3

9 files changed

Lines changed: 151 additions & 118 deletions

File tree

‎README.md‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,41 @@ Commands:
9999

100100
<!-- CONTRIBUTING -->
101101

102+
## Building
103+
104+
This project uses Deno for development and compilation. Make sure you have Deno
105+
installed on your system before proceeding.
106+
107+
### Running the Project
108+
109+
To run the project whilst developing:
110+
111+
```
112+
deno run --allow-env --allow-read --allow-write --allow-net src/cli.ts <OPTIONS>
113+
```
114+
115+
You can specify the desired Deno permissions flags to limit the functionality of
116+
the CLI. To disable the Deno permissions system, use `-A` (allow-all) instead:
117+
118+
```
119+
deno run -A src/cli.ts
120+
```
121+
122+
### Building a release version
123+
124+
To build a statically compiled binary:
125+
126+
```
127+
deno compile --allow-env --allow-read --allow-write --allow-net -o apw src/cli.ts
128+
```
129+
130+
You can specify the desired Deno permissions flags to limit the functionality of
131+
the CLI. To disable the Deno permissions system, use `-A` (allow-all) instead:
132+
133+
```
134+
deno compile -A -o apw src/cli.ts
135+
```
136+
102137
## Contributing
103138

104139
Contributions are what make the open source community such an amazing place to

‎deno.json‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
{}
1+
{
2+
"imports": {
3+
"@cliffy/command": "jsr:@cliffy/command@^1.0.0-rc.7",
4+
"@cliffy/prompt": "jsr:@cliffy/prompt@^1.0.0-rc.7"
5+
}
6+
}

‎deno.lock‎

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

‎src/cli.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
type RenamedPasswordEntry,
88
type TOTPEntry,
99
} from "./types.ts";
10-
import { APWError, Status } from "./const.ts";
10+
import { APWError, Status, VERSION } from "./const.ts";
1111

1212
const PrintEntries = (payload: Payload) => {
1313
if (payload.STATUS !== Status.SUCCESS) {
@@ -159,7 +159,7 @@ const auth = new Command()
159159
try {
160160
await new Command()
161161
.name("apw-cli")
162-
.version("0.1.0")
162+
.version(`v${VERSION}`)
163163
.description("🔑 a CLI for Apple Passwords 🔒")
164164
.command("auth", auth)
165165
.command("pw", pw)

‎src/client.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import { SRPSession } from "./srp.ts";
1111
import { readBigInt, readConfig, toBase64, toBuffer } from "./utils.ts";
1212
import { type Message, type SMSG } from "./types.ts";
13+
import { writeConfig } from "./utils.ts";
1314

1415
const BROWSER_NAME = "Arc";
1516
const VERSION = "1.0";
@@ -179,6 +180,7 @@ export class ApplePasswordManager {
179180

180181
constructor() {
181182
this.session = SRPSession.new(true);
183+
writeConfig({});
182184
const { username, sharedKey, port } = readConfig();
183185
this.remotePort = port;
184186
if (typeof sharedKey !== "bigint") return;
@@ -276,7 +278,7 @@ export class ApplePasswordManager {
276278
}
277279

278280
async verifyChallenge(password: string) {
279-
await this.session.setSharedKey(password);
281+
const newKey = await this.session.setSharedKey(password);
280282

281283
const m = await this.session.computeM();
282284
const msg = await APWMessages.verifyChallenge(this.session, m);
@@ -327,6 +329,11 @@ export class ApplePasswordManager {
327329
"Invalid server verification: HAMK mismatch",
328330
);
329331
}
332+
console.log("Challenge verified, updating config");
333+
await writeConfig({
334+
username: this.session.username.toString(),
335+
sharedKey: newKey,
336+
});
330337
}
331338

332339
async getLoginNamesForURL(url: string) {

‎src/const.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export const DATA_PATH = `${Deno.env.get("HOME")}/.apw`;
22

3+
export const VERSION = "1.0.0";
4+
35
export class APWError extends Error {
46
code: Status;
57
constructor(public status: Status, message?: string) {

‎src/deps.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
export { Command } from "https://deno.land/x/cliffy@v1.0.0-rc.3/command/mod.ts";
2-
export {
3-
Input,
4-
Select,
5-
} from "https://deno.land/x/cliffy@v1.0.0-rc.3/prompt/mod.ts";
1+
export { Command } from "@cliffy/command";
2+
export { Input, Select } from "@cliffy/prompt";
63
export { Buffer } from "node:buffer";
74
export { createSocket, type RemoteInfo } from "node:dgram";
85
export { existsSync } from "node:fs";

‎src/srp.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
readBigInt,
88
sha256,
99
toBuffer,
10-
writeConfig,
1110
} from "./utils.ts";
1211
import { APWError, Status } from "./const.ts";
1312
import { SRPValues } from "./types.ts";
@@ -162,10 +161,6 @@ export class SRPSession {
162161
);
163162

164163
this.sharedKey = readBigInt(await sha256(premasterSecret));
165-
await writeConfig({
166-
username: this.username.toString(),
167-
sharedKey: this.sharedKey,
168-
});
169164
return this.sharedKey;
170165
}
171166

‎src/utils.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,18 @@ export const clearConfig = async () => {
7979
}
8080
};
8181

82-
export const writeConfig = async (
82+
export const writeConfig = (
8383
{ username, sharedKey, port }: {
8484
username?: string;
8585
sharedKey?: bigint;
8686
port?: number;
8787
},
8888
) => {
8989
let existingConfig: APWConfig;
90-
await Deno.mkdir(DATA_PATH, { recursive: true });
90+
Deno.mkdirSync(DATA_PATH, { recursive: true });
9191
try {
9292
existingConfig = JSON.parse(
93-
await Deno.readTextFile(`${DATA_PATH}/config.json`),
93+
Deno.readTextFileSync(`${DATA_PATH}/config.json`),
9494
);
9595
} catch (_) {
9696
existingConfig = { sharedKey: "", username: "" };
@@ -101,7 +101,7 @@ export const writeConfig = async (
101101
sharedKey: sharedKey ? toBase64(sharedKey) : existingConfig.sharedKey,
102102
port: port || existingConfig.port || 10000,
103103
};
104-
await Deno.writeTextFile(
104+
Deno.writeTextFileSync(
105105
`${DATA_PATH}/config.json`,
106106
JSON.stringify(updatedConfig),
107107
);

0 commit comments

Comments
 (0)