Skip to content

Commit

Permalink
fix: Add Cere Wallet backup file support in token generation command
Browse files Browse the repository at this point in the history
  • Loading branch information
skambalin committed Sep 11, 2024
1 parent af47185 commit 3837a3b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/cli/src/token.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { AuthToken, AuthTokenOperation, UriSigner, AuthTokenParams, Cid } from '@cere-ddc-sdk/ddc';
import { AuthToken, AuthTokenOperation, AuthTokenParams, Cid } from '@cere-ddc-sdk/ddc';

import { createSigner } from './createClient';

export type TokenOptions = Omit<AuthTokenParams, 'bucketId' | 'operations'> & {
signer?: string;
signerType?: string;
signerPassphrase?: string;
bucketId?: string;
operations: string[];
};
Expand Down Expand Up @@ -33,12 +36,6 @@ export const decodeToken = async (token: string) => {
};

export const createToken = async (options: TokenOptions) => {
const signer =
options.signer &&
new UriSigner(options.signer, {
type: options.signerType === 'ed25519' ? 'ed25519' : 'sr25519',
});

if (options.pieceCid && !Cid.isCid(options.pieceCid)) {
throw new Error('Invalid CID');
}
Expand All @@ -53,7 +50,10 @@ export const createToken = async (options: TokenOptions) => {
operations: options.operations.map((op) => operationsMap[op]),
});

if (signer) {
if (options.signer) {
const signer = await createSigner(options.signer, options.signerType);

await signer.unlock(options.signerPassphrase);
await token.sign(signer);
}

Expand Down

0 comments on commit 3837a3b

Please sign in to comment.