-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from nabla-studio/DavideSegullo/feat-xdefi_wallet
Add xdefi wallet
- Loading branch information
Showing
10 changed files
with
213 additions
and
20 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './keplr'; | ||
export * from './leap'; | ||
export * from './cosmostation'; | ||
export * from './xdefi'; |
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,141 @@ | ||
import type { | ||
OfflineAminoSigner, | ||
StdSignDoc, | ||
AminoSignResponse, | ||
StdSignature, | ||
} from '@cosmjs/amino'; | ||
import type { | ||
OfflineDirectSigner, | ||
DirectSignResponse, | ||
} from '@cosmjs/proto-signing'; | ||
import type { Key, SignOptions, WalletOptions } from '@quirks/core'; | ||
import { ExtensionWallet, assertIsDefined } from '@quirks/core'; | ||
import type { SignDoc } from 'cosmjs-types/cosmos/tx/v1beta1/tx'; | ||
import Long from 'long'; | ||
import type { XDEFI } from './types'; | ||
|
||
export class XDEFIWalletExtension extends ExtensionWallet<XDEFI> { | ||
constructor(options: WalletOptions) { | ||
super(options); | ||
} | ||
|
||
override enable(chainIds: string[]): Promise<void> { | ||
assertIsDefined(this.client); | ||
|
||
return this.client.enable(chainIds); | ||
} | ||
|
||
override disable(chainIds: string[]): Promise<void> { | ||
assertIsDefined(this.client); | ||
|
||
return this.client.disable(chainIds); | ||
} | ||
|
||
override async getAccount(chainId: string) { | ||
assertIsDefined(this.client); | ||
|
||
return await this.client.getKey(chainId); | ||
} | ||
|
||
override async getAccounts(chainIds: string[]) { | ||
assertIsDefined(this.client); | ||
|
||
const keys = await this.client.getKeysSettled(chainIds); | ||
|
||
return keys | ||
.map((key) => { | ||
if (key.status === 'fulfilled') { | ||
return key.value; | ||
} | ||
|
||
return undefined; | ||
}) | ||
.filter((key) => key !== undefined) as Key[]; | ||
} | ||
|
||
override async getOfflineSigner( | ||
chainId: string, | ||
options?: SignOptions | undefined, | ||
): Promise<OfflineAminoSigner & OfflineDirectSigner> { | ||
assertIsDefined(this.client); | ||
|
||
return await this.client.getOfflineSigner(chainId, options); | ||
} | ||
|
||
override async getOfflineSignerOnlyAmino( | ||
chainId: string, | ||
options?: SignOptions | undefined, | ||
): Promise<OfflineAminoSigner> { | ||
assertIsDefined(this.client); | ||
|
||
return await this.client.getOfflineSignerOnlyAmino(chainId, options); | ||
} | ||
|
||
override getOfflineSignerAuto( | ||
chainId: string, | ||
options?: SignOptions | undefined, | ||
): Promise<OfflineAminoSigner | OfflineDirectSigner> { | ||
assertIsDefined(this.client); | ||
|
||
return this.client.getOfflineSignerAuto(chainId, options); | ||
} | ||
|
||
override signAmino( | ||
chainId: string, | ||
signer: string, | ||
signDoc: StdSignDoc, | ||
signOptions?: SignOptions | undefined, | ||
): Promise<AminoSignResponse> { | ||
assertIsDefined(this.client); | ||
|
||
return this.client.signAmino(chainId, signer, signDoc, signOptions); | ||
} | ||
|
||
override signDirect( | ||
chainId: string, | ||
signer: string, | ||
signDoc: SignDoc, | ||
signOptions?: SignOptions | undefined, | ||
): Promise<DirectSignResponse> { | ||
assertIsDefined(this.client); | ||
|
||
return this.client.signDirect( | ||
chainId, | ||
signer, | ||
{ | ||
...signDoc, | ||
accountNumber: Long.fromString(signDoc.accountNumber.toString(10)), | ||
}, | ||
signOptions, | ||
); | ||
} | ||
|
||
override signArbitrary( | ||
chainId: string, | ||
signer: string, | ||
data: string | Uint8Array, | ||
): Promise<StdSignature> { | ||
assertIsDefined(this.client); | ||
|
||
return this.client.signArbitrary(chainId, signer, data); | ||
} | ||
|
||
override verifyArbitrary( | ||
chainId: string, | ||
signer: string, | ||
data: string | Uint8Array, | ||
signature: StdSignature, | ||
): Promise<boolean> { | ||
assertIsDefined(this.client); | ||
|
||
return this.client.verifyArbitrary(chainId, signer, data, signature); | ||
} | ||
|
||
override async suggestTokens(): Promise<void> { | ||
console.warn("xDefi doesn't support suggestTokens"); | ||
} | ||
|
||
override async suggestChains(): Promise<void> { | ||
console.warn("xDefi doesn't support suggestChains"); | ||
} | ||
} |
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,6 @@ | ||
import { XDEFIWalletExtension } from './extension'; | ||
import { xdefiExtensionOptions } from './registry'; | ||
|
||
const xdefiExtension = new XDEFIWalletExtension(xdefiExtensionOptions); | ||
|
||
export { xdefiExtension }; |
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,24 @@ | ||
import { WalletConnectionTypes, type WalletOptions } from '@quirks/core'; | ||
|
||
export const xdefiExtensionOptions: WalletOptions = { | ||
name: 'xdefi-extension', | ||
prettyName: 'XDEFI', | ||
connectionType: WalletConnectionTypes.EXTENSION, | ||
windowKey: 'xfi.keplr', | ||
downloads: [ | ||
{ | ||
link: 'https://chrome.google.com/webstore/detail/xdefi-wallet/hmeobnfnfcmdkdcmlblgagmfpfboieaf', | ||
}, | ||
], | ||
logoUrls: { | ||
light: { | ||
jpg: 'https://lh3.googleusercontent.com/6TkuRn_tZ2v5Bw4MZ2nTwJLEWU-76bAQFJhXunA7cbroI0izn7Mwi46Wvu3q5WfNUbQiPucQTCSTrb0FD_BCXuo3=w128-h128-e365-rj-sc0x00ffffff', | ||
}, | ||
dark: { | ||
jpg: 'https://lh3.googleusercontent.com/6TkuRn_tZ2v5Bw4MZ2nTwJLEWU-76bAQFJhXunA7cbroI0izn7Mwi46Wvu3q5WfNUbQiPucQTCSTrb0FD_BCXuo3=w128-h128-e365-rj-sc0x00ffffff', | ||
}, | ||
}, | ||
events: { | ||
keystorechange: 'keplr_keystorechange', | ||
}, | ||
}; |
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,6 @@ | ||
import type { Keplr } from '@keplr-wallet/types'; | ||
|
||
export interface XDEFI extends Keplr { | ||
isXDEFI: boolean; | ||
disconnect: () => Promise<void>; | ||
} |