Skip to content

Commit

Permalink
feat: allow for fee based tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
coodos committed Apr 12, 2024
1 parent e5e6019 commit 4d809bf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanglelabs/ssimon",
"version": "0.7.0",
"version": "0.7.1",
"description": "SSIMON is an open, interoperable, and convenient software to manage DIDs and credentials",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
19 changes: 16 additions & 3 deletions src/identity-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,26 @@ export class IdentityManager<T extends IdentityAccount>
public async createDid<T extends StorageSpec<Record<string, any>, any>>(
props: CreateDidProps<T>
): Promise<IdentityAccount> {
if (await this.storage.findOne({ alias: props.alias }))
throw new Error("Alias already exists");
const aliasExists = await this.storage.findOne({ alias: props.alias });
if (aliasExists) {
const isTemp = aliasExists.did.split(":")[2].startsWith("TEMP");
if (!isTemp) throw new Error("Alias already exists");
}
await this.storage.create({ alias: props.alias });
if (!Object.keys(this.networkAdapters).includes(props.method))
throw new Error("DID Method not supported");
const adapter = this.networkAdapters[props.method];
const { identity, seed } = await adapter.createDid(props);
const { identity, seed } = await adapter
.createDid(props)
.catch(async (e) => {
if (e.name === "InsufficientFundsError") {
await this.storage.findOneAndUpdate(
{ alias: props.alias },
{ seed: e.seed, did: e.did }
);
}
throw e;
});

await this.storage.findOneAndUpdate(
{ alias: props.alias },
Expand Down

0 comments on commit 4d809bf

Please sign in to comment.