next-auth-hashpack
Version:
Authenticate with Hashpack wallet using NextAuthJs library.
63 lines (62 loc) • 2.52 kB
TypeScript
import { Awaitable, User } from "next-auth";
import { CredentialsConfig } from "next-auth/providers/credentials";
export type HederaNetworkType = 'mainnet' | 'testnet' | 'previewnet';
export interface HashpackCredentialInputData {
signedPayload?: Uint8Array;
userSignature?: Uint8Array;
accountId?: string;
network?: HederaNetworkType;
}
export interface IGetUserPublicKey {
accountId: string;
network: HederaNetworkType;
}
export interface ICheckOriginalData {
accountId: string;
network: HederaNetworkType;
originalData: any;
}
export interface networkRelatedObject {
testnet: string;
mainnet: string;
previewnet?: string;
}
export interface HashpackOptions {
userReturnCallback: (credentials: HashpackCredentialInputData, userPublicKey?: string) => Awaitable<User | null>;
privateKey: string | networkRelatedObject | ((network: HederaNetworkType) => string);
mirrorNodeAccountInfoURL?: networkRelatedObject;
getUserPublicKey?: (({ accountId, network }: IGetUserPublicKey) => string | Promise<string>) | null;
checkOriginalData?: ({ accountId, network, originalData }: ICheckOriginalData) => boolean | Promise<boolean>;
debug?: boolean;
}
export type hashpackCredentialInputs = {
signedPayload: {
label: string;
type: string;
};
userSignature: {
label: string;
type: string;
};
accountId: {
label: string;
type: string;
};
network: {
label: string;
type: string;
};
};
/**
* config the credential to be used with hashpack wallet
*
* @param userReturnCallback a callback that return verified user
* @param privateKey Server's Hedera account private key, can be an object of privatekey strings for each networks
* @param mirrorNodeAccountInfoURL the mirror node api route for fetching account's info
* @param getUserPublicKey replace the fetching client user's public key mechanism
* @param checkOriginalData check the original data
*/
export declare const hashpackProvider: ({ userReturnCallback, privateKey, mirrorNodeAccountInfoURL, getUserPublicKey, checkOriginalData, debug }: HashpackOptions) => CredentialsConfig<hashpackCredentialInputs>;
export declare const debugging: (active: boolean, ...rest: any[]) => void;
export declare function isValidHederaAccount(accountId: string): boolean;
export declare const truncatePrivateKey: (privateKey: string) => string | false;