Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $ npm install -g solarium-cli
$ solarium COMMAND
running command...
$ solarium (-v|--version|version)
solarium-cli/0.1.11 darwin-x64 node-v16.0.0
solarium-cli/0.1.11 darwin-x64 node-v14.18.2
$ solarium --help [COMMAND]
USAGE
$ solarium COMMAND
Expand Down Expand Up @@ -50,8 +50,9 @@ ARGUMENTS
PUBLICKEY A public key in base-58 encoding

OPTIONS
-h, --help show CLI help
-n, --name=name (required) the key name (e.g. mobileDevice)
-f, --id_file=id_file Use this ID file
-h, --help show CLI help
-n, --name=name (required) the key name (e.g. mobileDevice)
```

_See code: [src/commands/add-key.ts](https://github.com/dankelleher/solarium/blob/v0.1.11/src/commands/add-key.ts)_
Expand All @@ -68,8 +69,9 @@ ARGUMENTS
WITH The DID to chat with

OPTIONS
-h, --help show CLI help
-m, --mute non-verbose input
-f, --id_file=id_file Use this ID file
-h, --help show CLI help
-m, --mute non-verbose input

ALIASES
$ solarium
Expand All @@ -86,7 +88,8 @@ USAGE
$ solarium create NAME

OPTIONS
-h, --help show CLI help
-f, --id_file=id_file Use this ID file
-h, --help show CLI help
```

_See code: [src/commands/create.ts](https://github.com/dankelleher/solarium/blob/v0.1.11/src/commands/create.ts)_
Expand Down Expand Up @@ -117,11 +120,12 @@ USAGE
$ solarium id

OPTIONS
-a, --alias=alias Set this ID's public alias
-c, --create Create a DID if missing
-h, --help show CLI help
-u, --update Update a DID's user details
-v, --verbose Show the entire DID document
-a, --alias=alias Set this ID's public alias
-c, --create Create a DID if missing
-f, --id_file=id_file Use this ID file
-h, --help show CLI help
-u, --update Update a DID's user details
-v, --verbose Show the entire DID document
```

_See code: [src/commands/id.ts](https://github.com/dankelleher/solarium/blob/v0.1.11/src/commands/id.ts)_
Expand All @@ -139,7 +143,8 @@ ARGUMENTS
CHANNEL The channel address

OPTIONS
-h, --help show CLI help
-f, --id_file=id_file Use this ID file
-h, --help show CLI help

EXAMPLE
solarium invite did:sol:<INVITEE> <CHANNEL_ADDRESS>
Expand All @@ -157,6 +162,7 @@ USAGE

OPTIONS
-c, --channel=channel (required) Channel address
-f, --id_file=id_file Use this ID file
-h, --help show CLI help
-i, --from-stdin
```
Expand All @@ -172,7 +178,8 @@ USAGE
$ solarium read CHANNEL

OPTIONS
-h, --help show CLI help
-f, --id_file=id_file Use this ID file
-h, --help show CLI help

ALIASES
$ solarium get
Expand All @@ -189,7 +196,8 @@ USAGE
$ solarium watch [CHANNEL]

OPTIONS
-h, --help show CLI help
-f, --id_file=id_file Use this ID file
-h, --help show CLI help
```

_See code: [src/commands/watch.ts](https://github.com/dankelleher/solarium/blob/v0.1.11/src/commands/watch.ts)_
Expand Down
13 changes: 10 additions & 3 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
},
"bugs": "https://github.com/dankelleher/solarium/issues",
"dependencies": {
"@identity.com/sol-did-client": "^1.0.0-beta",
"@oclif/command": "^1.8.0",
"@oclif/config": "^1.17.0",
"@oclif/plugin-help": "^3.2.2",
"@solana/web3.js": "^1.10.0",
"base-58": "^0.0.1",
"debug": "^4.3.1",
"did-resolver": "^3.1.0",
"dotenv": "^10.0.0",
"rxjs": "^7.0.0",
"rxjs-stream": "^3.2.1",
"solarium-js": "^0.1.26",
"solarium-js": "file:../client",
"start-server-and-test": "^1.14.0",
"tslib": "^1"
},
"devDependencies": {
Expand All @@ -38,6 +42,7 @@
"mocha": "^5",
"nyc": "^14",
"prettier": "^2.3.2",
"sinon": "^12.0.1",
"ts-node": "^9.1.1",
"typescript": "^4.2.4"
},
Expand Down Expand Up @@ -72,9 +77,11 @@
"postpack": "rm -f oclif.manifest.json",
"posttest": "eslint . --ext .ts --config .eslintrc",
"prepack": "yarn build && oclif-dev manifest",
"test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
"test-with-validator": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\" -r dotenv/config",
"version": "oclif-dev readme && git add README.md",
"lint": "eslint src/ test/"
"lint": "eslint src/ test/",
"test": "start-server-and-test start-validator http://localhost:8899/health test-with-validator",
"start-validator": "solana-test-validator --bpf-program dbo6b6DDmWTWpLcZM5SoVEf9X8DSJYPjVfD3Ptz6hod ./test/solarium.so --bpf-program ide3Y2TubNMLLhiG1kDL6to4a8SjxD18YWCYC5BZqNV ./test/sol_did.so --reset"
},
"types": "lib/index.d.ts"
}
6 changes: 5 additions & 1 deletion cli/src/commands/add-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export default class AddKey extends Command {
char: "n",
description: "the key name (e.g. mobileDevice)",
}),
id_file: flags.string({
char: "f",
description: "Use this ID file",
}),
};

static args = [
Expand All @@ -21,7 +25,7 @@ export default class AddKey extends Command {
async run(): Promise<void> {
const { args, flags } = this.parse(AddKey);

await service.addKey(flags.name, args.publicKey);
await service.addKey(flags.name, args.publicKey, flags.id_file);

console.log("Added key");
}
Expand Down
10 changes: 9 additions & 1 deletion cli/src/commands/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export default class Chat extends Command {
static flags = {
help: flags.help({ char: "h" }),
mute: flags.boolean({ char: "m", description: "non-verbose input" }),
id_file: flags.string({
char: "f",
description: "Use this ID file",
}),
};

static args = [
Expand All @@ -21,7 +25,11 @@ export default class Chat extends Command {

const incomingMessages = streamToStringRx(process.stdin);

const messages = await service.chat(args.with, incomingMessages);
const messages = await service.chat(
args.with,
incomingMessages,
flags.id_file
);

messages.subscribe((message) => {
if (flags.mute) {
Expand Down
8 changes: 6 additions & 2 deletions cli/src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ export default class Create extends Command {

static flags = {
help: flags.help({ char: "h" }),
id_file: flags.string({
char: "f",
description: "Use this ID file",
}),
};

static args = [{ name: "name", required: true }];

async run(): Promise<void> {
const { args } = this.parse(Create);
const { args, flags } = this.parse(Create);

const channel = await service.create(args.name);
const channel = await service.create(args.name, flags.id_file);

console.log(`Created channel ${args.name}: ${channel.address.toBase58()}`);
}
Expand Down
10 changes: 7 additions & 3 deletions cli/src/commands/id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,25 @@ export default class Id extends Command {
char: "v",
description: "Show the entire DID document",
}),
id_file: flags.string({
char: "f",
description: "Use this ID file",
}),
};

async run(): Promise<void> {
const { flags } = this.parse(Id);

if (flags.create) {
const extendedId = await service.createId(flags.alias);
const extendedId = await service.createId(flags.alias, flags.id_file);
report(extendedId, flags.verbose);
} else if (flags.update) {
if (!flags.alias)
throw new Error("Missing alias. Try: solarium id -u -a <NEW ALIAS>");
await service.updateId(flags.alias);
await service.updateId(flags.alias, flags.id_file);
console.log("Updated");
} else {
const extendedId = await service.getId();
const extendedId = await service.getId(flags.id_file);
if (!extendedId) {
console.log("You have no DID - create one with: solarium id -c");
} else {
Expand Down
8 changes: 6 additions & 2 deletions cli/src/commands/invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export default class Invite extends Command {

static flags = {
help: flags.help({ char: "h" }),
id_file: flags.string({
char: "f",
description: "Use this ID file",
}),
};

static args = [
Expand All @@ -15,9 +19,9 @@ export default class Invite extends Command {
];

async run(): Promise<void> {
const { args } = this.parse(Invite);
const { args, flags } = this.parse(Invite);

await service.invite(args.invitee, args.channel);
await service.invite(args.invitee, args.channel, flags.id_file);

console.log(`Added ${args.invitee} to channel ${args.channel}`);
}
Expand Down
8 changes: 6 additions & 2 deletions cli/src/commands/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export default class Post extends Command {
}),
// -i, --from-stdin
"from-stdin": flags.boolean({ char: "i" }),
id_file: flags.string({
char: "f",
description: "Use this ID file",
}),
};

static args = [{ name: "message" }];
Expand All @@ -23,10 +27,10 @@ export default class Post extends Command {

if (flags["from-stdin"]) {
process.stdin.on("data", async (data: string) => {
await service.post(data, flags.channel);
await service.post(data, flags.channel, flags.id_file);
});
} else {
await service.post(args.message, flags.channel);
await service.post(args.message, flags.channel, flags.id_file);
}
}
}
8 changes: 6 additions & 2 deletions cli/src/commands/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ export default class Read extends Command {

static flags = {
help: flags.help({ char: "h" }),
id_file: flags.string({
char: "f",
description: "Use this ID file",
}),
};

static args = [{ name: "channel", required: true }];
static aliases = ["get"];

async run(): Promise<void> {
const { args } = this.parse(Read);
const { args, flags } = this.parse(Read);

const messages = await service.read(args.channel);
const messages = await service.read(args.channel, flags.id_file);

messages
.map((m) => `From: ${m.sender}: ${m.content}`)
Expand Down
8 changes: 6 additions & 2 deletions cli/src/commands/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ export default class Watch extends Command {

static flags = {
help: flags.help({ char: "h" }),
id_file: flags.string({
char: "f",
description: "Use this ID file",
}),
};

static args = [{ name: "channel" }];

async run(): Promise<void> {
const { args } = this.parse(Watch);
const { args, flags } = this.parse(Watch);

const messages = await service.readStream(args.channel);
const messages = await service.readStream(args.channel, flags.id_file);

messages.subscribe((message: Message) => {
console.log(`From: ${message.sender}: ${message.content}`);
Expand Down
24 changes: 17 additions & 7 deletions cli/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,44 @@ export const getDefaultSolanaWallet = (): Keypair => {
});
const parsedConfig = parseConfig(solanaConfig.toString("utf-8"));

debug(`getDefaultSolanaWallet parsedConfig=${solanaConfig}`);

// eslint-disable-next-line @typescript-eslint/no-var-requires
const secretKey = require(parsedConfig.keypairPath);

return Keypair.fromSecretKey(Buffer.from(secretKey));
};

// If the user has a wallet in their .solarium folder, use that
export const getSolariumWallet = (): Keypair => {
export const getSolariumWallet = (id_file?: string): Keypair => {
const path = (id_file || DEFAULT_KEYPAIR_FILE) as string;
// eslint-disable-next-line @typescript-eslint/no-var-requires
const secretKey = require(DEFAULT_KEYPAIR_FILE);
const secretKey = require(path);

debug("Using keypair in $HOME/.solarium");
const keypair = Keypair.fromSecretKey(Buffer.from(secretKey));

return Keypair.fromSecretKey(Buffer.from(secretKey));
debug(`Using keypair in ${path} publicKey=${keypair.publicKey}`);

return keypair;
};

export const getWallet = async (): Promise<Keypair> => {
export const getWallet = async (id_file?: string): Promise<Keypair> => {
if (id_file) {
debug(`getWallet using ${id_file}`);
return getSolariumWallet(id_file);
}

try {
return getDefaultSolanaWallet();
} catch (defaultSolanaError) {
} catch (defaultSolanaError: any) {
if (defaultSolanaError.message.indexOf("command not found")) {
debug(
"Solana CLI not found on path - looking for a keypair in $HOME/.solarium"
);

try {
return getSolariumWallet();
} catch (solariumWalletError) {
} catch (solariumWalletError: any) {
if (solariumWalletError.code === "MODULE_NOT_FOUND") {
debug("No keypair found in $HOME/.solarium - creating...");
const generatedKeypair = await createWallet();
Expand Down
5 changes: 3 additions & 2 deletions cli/src/service/addKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import * as solarium from "solarium-js";

export const addKey = async (
keyIdentifier: string,
newKey: string
newKey: string,
id_file?: string
): Promise<void> => {
const wallet = await getWallet();
const wallet = await getWallet(id_file);

await solarium.addKey({
payer: wallet.secretKey,
Expand Down
Loading