2018-10-01 14:01:20 -07:00
|
|
|
export enum AUTH_PROVIDER {
|
|
|
|
WEB3 = 'WEB3',
|
|
|
|
LEDGER = 'LEDGER',
|
|
|
|
TREZOR = 'TREZOR',
|
|
|
|
ADDRESS = 'ADDRESS',
|
|
|
|
}
|
|
|
|
|
|
|
|
interface AuthProvider {
|
|
|
|
type: AUTH_PROVIDER;
|
|
|
|
name: string;
|
|
|
|
canSignMessage: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const AUTH_PROVIDERS: { [key in AUTH_PROVIDER]: AuthProvider } = {
|
|
|
|
[AUTH_PROVIDER.WEB3]: {
|
|
|
|
type: AUTH_PROVIDER.WEB3,
|
|
|
|
name: 'MetaMask', // TODO: Set dynamically based on provider
|
|
|
|
canSignMessage: true,
|
|
|
|
},
|
|
|
|
[AUTH_PROVIDER.LEDGER]: {
|
|
|
|
type: AUTH_PROVIDER.LEDGER,
|
|
|
|
name: 'Ledger',
|
|
|
|
canSignMessage: true,
|
|
|
|
},
|
|
|
|
[AUTH_PROVIDER.TREZOR]: {
|
|
|
|
type: AUTH_PROVIDER.TREZOR,
|
|
|
|
name: 'TREZOR',
|
|
|
|
canSignMessage: true,
|
|
|
|
},
|
|
|
|
[AUTH_PROVIDER.ADDRESS]: {
|
|
|
|
type: AUTH_PROVIDER.ADDRESS,
|
|
|
|
name: 'Address',
|
|
|
|
canSignMessage: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-10-30 16:18:26 -07:00
|
|
|
export function generateAuthSignatureData(address: string) {
|
|
|
|
const message = `I am proving the identity of ${address} on Grant.io`;
|
|
|
|
const time = new Date().toUTCString();
|
|
|
|
return {
|
|
|
|
data: { message, time },
|
|
|
|
types: {
|
2018-11-07 11:08:42 -08:00
|
|
|
authorization: [
|
|
|
|
{
|
|
|
|
name: 'Message Proof',
|
|
|
|
type: 'string',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Time',
|
|
|
|
type: 'string',
|
|
|
|
},
|
|
|
|
],
|
2018-10-30 16:18:26 -07:00
|
|
|
},
|
2018-11-07 11:08:42 -08:00
|
|
|
primaryType: 'authorization',
|
2018-10-30 16:18:26 -07:00
|
|
|
};
|
2018-10-01 14:01:20 -07:00
|
|
|
}
|