-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
38 changed files
with
2,180 additions
and
507 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export const CORE_POLLING_INTERVAL = 5_000; | ||
export const SUPPORTED_METAMASK_VERSION = '11.5.0'; |
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 +1,2 @@ | ||
export * from './snap'; | ||
export * from './general'; |
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 @@ | ||
export const defaultSnapOrigin = 'npm:@rarimo/rarime'; |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './snap'; |
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,11 @@ | ||
export enum RPCMethods { | ||
CreateIdentity = 'create_identity', | ||
SaveCredentials = 'save_credentials', | ||
RemoveCredentials = 'remove_credentials', | ||
CheckCredentialExistence = 'check_credential_existence', | ||
CreateProof = 'create_proof', | ||
CheckStateContractSync = 'check_state_contract_sync', | ||
GetCredentials = 'get_credentials', | ||
ExportIdentity = 'export_identity', | ||
GetIdentity = 'get_identity', | ||
} |
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 +1,3 @@ | ||
export * from './state-v2-helpers'; | ||
export * from './snap'; | ||
export * from './promise'; | ||
export * from './error-helper'; |
File renamed without changes.
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,5 @@ | ||
import { MetamaskSnap } from './snap'; | ||
import { checkSnapSupport, isMetamaskInstalled } from './utils'; | ||
import versionJson from './version.json'; | ||
|
||
export { MetamaskSnap } from './snap'; | ||
export * from './helpers'; | ||
export * from './consts'; | ||
export * from './enums'; | ||
export * from './types'; | ||
export { isMetamaskInstalled, isSnapInstalled } from './utils'; | ||
|
||
export const defaultSnapOrigin = 'npm:@rarimo/rarime'; | ||
|
||
export const enableSnap = async ( | ||
snapOrigin?: string, | ||
version = versionJson.version, | ||
): Promise<MetamaskSnap> => { | ||
const snapId = snapOrigin ?? defaultSnapOrigin; | ||
|
||
if (!(await isMetamaskInstalled())) { | ||
throw new Error('Metamask is not installed'); | ||
} | ||
|
||
if (!(await checkSnapSupport())) { | ||
throw new Error('Current version of MetaMask is not supported'); | ||
} | ||
|
||
await window.ethereum.request({ | ||
method: 'wallet_requestSnaps', | ||
params: { | ||
[snapId]: { ...(version && { version }) }, | ||
}, | ||
}); | ||
|
||
return new MetamaskSnap(snapId); | ||
}; | ||
export * from './zkp'; |
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 @@ | ||
export * from './snap'; |
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 @@ | ||
import versionJson from '../version.json'; | ||
|
||
import { defaultSnapOrigin } from '@/consts'; | ||
import type { RPCMethods } from '@/enums'; | ||
import { | ||
checkSnapSupport, | ||
getProvider, | ||
getWalletSnaps, | ||
isMetamaskInstalled, | ||
} from '@/helpers'; | ||
import type { SnapRequestParams, SnapRequestsResponses } from '@/types'; | ||
|
||
export class RarimeSnapBase { | ||
public readonly snapId: string; | ||
|
||
public readonly version: string; | ||
|
||
public constructor( | ||
snapId = defaultSnapOrigin, | ||
version = versionJson.version, | ||
) { | ||
this.snapId = snapId; | ||
this.version = version; | ||
} | ||
|
||
public async sendSnapRequest<Method extends RPCMethods>( | ||
method: Method, | ||
params?: SnapRequestParams[Method], | ||
): Promise<SnapRequestsResponses[Method]> { | ||
const provider = await getProvider(); | ||
|
||
return await provider.request({ | ||
method: 'wallet_invokeSnap', | ||
params: { | ||
request: { | ||
method, | ||
params, | ||
}, | ||
snapId: this.snapId, | ||
}, | ||
}); | ||
} | ||
|
||
public async enable() { | ||
const snapId = this.snapId ?? defaultSnapOrigin; | ||
|
||
if (!(await isMetamaskInstalled())) { | ||
throw new Error('Metamask is not installed'); | ||
} | ||
|
||
if (!(await checkSnapSupport())) { | ||
throw new Error('Current version of MetaMask is not supported'); | ||
} | ||
|
||
const provider = await getProvider(); | ||
|
||
return await provider.request({ | ||
method: 'wallet_requestSnaps', | ||
params: { | ||
[snapId]: { ...(this.version && { version: this.version }) }, | ||
}, | ||
}); | ||
} | ||
|
||
async isInstalled() { | ||
try { | ||
await getProvider(); | ||
|
||
const walletSnaps = await getWalletSnaps(); | ||
|
||
return Boolean( | ||
Object.values(walletSnaps).find( | ||
(permission) => | ||
permission.id === this.snapId && | ||
(!this.version || permission.version === this.version), | ||
), | ||
); | ||
} catch (error) { | ||
console.log('Failed to obtain installed snaps', error); | ||
return false; | ||
} | ||
} | ||
} |
Oops, something went wrong.