@citizenwallet/sdk
Version:
An sdk to easily work with citizen wallet.
50 lines • 2.31 kB
TypeScript
import { type BaseWallet } from "ethers";
import { type CommunityConfig } from "../config";
export interface Voucher {
alias: string;
creator: string;
account: string;
name: string;
}
/**
* Parses a voucher from a given data string (typically a URL).
*
* @param data - A string containing the voucher data, usually in URL format.
* @returns An object containing the parsed voucher information and a signer.
* @throws Error if the voucher data is invalid or incomplete.
*
* @remarks
* This function performs the following steps:
* 1. Parses the input string as a URL.
* 2. Extracts and decodes the voucher key (signer's private key).
* 3. Creates a signer from the decoded key.
* 4. Extracts and decodes the voucher parameters.
* 5. Constructs a Voucher object from the decoded parameters.
* 6. Validates the voucher data for completeness.
*/
export declare const parseVoucher: (data: string) => {
voucher: Voucher;
signer: BaseWallet;
};
/**
* Creates a voucher for a given community.
*
* @param config - The config of the community for which the voucher is created.
* @param voucherName - The name of the voucher.
* @param voucherCreator - The account address of creator. Since the user redeeming the voucher will only see a transaction from the voucher to them, this allows to display the original creator.
* @param voucherSigner - A newly generated wallet that will be used to sign transactions for this voucher.
* @returns An object containing the voucher link and the voucher account address.
*
* @remarks
* - A new voucherSigner (wallet) should be generated for each voucher to ensure security.
* - This function creates a voucher but does not fund it. Tokens need to be sent to the
* voucher account address for it to be considered "unredeemed". Without funds, the voucher
* will be considered "redeemed" or empty.
* - The voucherSigner's private key is included in the voucher link, so it's crucial to generate
* a new key for each voucher to prevent reuse and potential security issues.
*/
export declare const createVoucher: (config: CommunityConfig, voucherName: string, voucherCreator: string, voucherSigner: BaseWallet) => Promise<{
voucherLink: string;
voucherAccountAddress: string;
}>;
//# sourceMappingURL=index.d.ts.map