-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2aff2b8
commit 04c7775
Showing
10 changed files
with
1,211 additions
and
1 deletion.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
|
||
export default function getKeplrProvider() { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const handleRequest = (request: Record<string, any>) => | ||
new Promise((resolve, reject) => { | ||
const id = Math.random(); | ||
const handler = (e: MessageEvent) => { | ||
if (e.data.__page_req_id === id && e.data.__direction === 'to_page') { | ||
window.removeEventListener('message', handler); | ||
if (e.data.__error) { | ||
const {module, code, message} = e.data.__error; | ||
return reject({module, code, message}); | ||
} | ||
delete e.data.__page_req_id; | ||
delete e.data.__direction; | ||
resolve(Object.keys(e.data).length > 0 ? e.data : undefined); | ||
} | ||
}; | ||
|
||
window.addEventListener('message', handler); | ||
|
||
window.postMessage({ | ||
...request, | ||
__message_type: 'rpc', | ||
__provider: 'keplr', | ||
__page_req_id: id, | ||
__direction: 'to_bg' | ||
}); | ||
}); | ||
return { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
enable: async function (chainIds: string | string[]) { | ||
return handleRequest({ | ||
method: `keplr_enable as string}`, | ||
params: [chainIds] | ||
}); | ||
}, | ||
getKey: async function (chainId: string) { | ||
return handleRequest({ | ||
method: 'keplr_getKey', | ||
params: [chainId] | ||
}); | ||
} | ||
}; | ||
// enable(chainIds: string | string[]): Promise<void>, | ||
// getKey(chainId: string): Promise<{ | ||
// signAmino(chainId: string, signer: string, signDoc: StdSignDoc): Promise<AminoSignResponse> | ||
// signDirect(chainId:string, signer:string, signDoc: { | ||
// sendTx( | ||
// chainId: string, | ||
// tx: Uint8Array, | ||
// mode: BroadcastMode | ||
// ): Promise<Uint8Array>; { | ||
// handleRequest({ | ||
// method: 'keplr_sendTx', | ||
// params: [[chainId, tx, mode].toJSON()] | ||
// }) | ||
// resutl =await keplerClient[method.split("_")[1]] (...params) | ||
|
||
// sendBack(result) | ||
|
||
// } | ||
// signArbitrary( | ||
// chainId: string, | ||
// signer: string, | ||
// data: string | Uint8Array | ||
// ): Promise<StdSignature>; | ||
// verifyArbitrary( | ||
// chainId: string, | ||
// signer: string, | ||
// data: string | Uint8Array, | ||
// signature: StdSignature | ||
// ): Promise<boolean>; | ||
// }; | ||
// signEthereum( | ||
// chainId: string, | ||
// signer: string, // Bech32 address, not hex | ||
// data: string | Uint8Array, | ||
// type: 'message' | 'transaction' | ||
// ) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,6 @@ declare global { | |
point: any; | ||
ethereum: any; | ||
solana: any; | ||
keplr: any; | ||
} | ||
} |