-
Notifications
You must be signed in to change notification settings - Fork 2
feat(audit-trail): initialize wasm client and integrate into context #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alexruzenhack
wants to merge
3
commits into
feat/audit-trail-config
Choose a base branch
from
feat/audit-trail-wasm
base: feat/audit-trail-config
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,17 +5,22 @@ import * as identity from '@iota/identity-wasm/web'; | |||||
| import identityWasmUrl from '@iota/identity-wasm/web/identity_wasm_bg.wasm?url'; | ||||||
| import * as notarization from '@iota/notarization/web'; | ||||||
| import notarizationWasmUrl from '@iota/notarization/web/notarization_wasm_bg.wasm?url'; | ||||||
| import * as auditTrail from '@iota/audit-trails/web'; | ||||||
| import auditTrailWasmUrl from '@iota/audit-trails/web/audit_trail_wasm_bg.wasm?url'; | ||||||
| import { type IotaClient, Network } from '@iota/iota-sdk/client'; | ||||||
| import { | ||||||
| DID_PROTOCOL_SEGMENT_SYMBOL, | ||||||
| DID_URL_SEGMENT_SYMBOL, | ||||||
| IOTA_IDENTITY_PKG_ID, | ||||||
| IOTA_NOTARIZATION_PKG_ID, | ||||||
| IOTA_AUDIT_TRAIL_PKG_ID, | ||||||
| IOTA_TF_COMPONENTS_PKG_ID, | ||||||
| } from '~/lib/constants/trustFramework.constants'; | ||||||
|
|
||||||
| const regularNetworks = new Set([Network.Mainnet, Network.Testnet, Network.Devnet]); | ||||||
| let initIdentityPromise: Promise<void> | null = null; | ||||||
| let initNotarizationPromise: Promise<void> | null = null; | ||||||
| let initAuditTrailPromise: Promise<void> | null = null; | ||||||
|
|
||||||
| /** | ||||||
| * Idempotent initialization of WASM module of Identity. | ||||||
|
|
@@ -49,6 +54,22 @@ export const initNotarizationWasmWeb = async (): Promise<void> => { | |||||
| return initNotarizationPromise; | ||||||
| }; | ||||||
|
|
||||||
| /** | ||||||
| * Idempotent initialization of WASM module of Audit Trail. | ||||||
| * | ||||||
| * Use it everytime you need to call any audit trail API. | ||||||
| */ | ||||||
| export const initAuditTrailWasmWeb = async (): Promise<void> => { | ||||||
| if (!initAuditTrailPromise) { | ||||||
| initAuditTrailPromise = auditTrail.init(auditTrailWasmUrl).catch((e) => { | ||||||
| console.error('failed to load audit trail wasm (web version)', e); | ||||||
| initAuditTrailPromise = null; // allow retry | ||||||
| throw e; | ||||||
| }); | ||||||
| } | ||||||
| return initAuditTrailPromise; | ||||||
| }; | ||||||
|
|
||||||
| export const createIdentityClientReadOnly = async ( | ||||||
| iotaClient: IotaClient, | ||||||
| network: string, | ||||||
|
|
@@ -95,6 +116,29 @@ export const createNotarizationClientReadOnly = async ( | |||||
| ); | ||||||
| }; | ||||||
|
|
||||||
| export const createAuditTrailClientReadOnly = async ( | ||||||
| iotaClient: IotaClient, | ||||||
| network: string, | ||||||
| ): Promise<auditTrail.AuditTrailClientReadOnly> => { | ||||||
| // If IOTA_AUDIT_TRAIL_PKG_ID is declared it has precedence | ||||||
| await initAuditTrailWasmWeb(); | ||||||
| if (IOTA_AUDIT_TRAIL_PKG_ID != null && IOTA_TF_COMPONENTS_PKG_ID != null) { | ||||||
| return await auditTrail.AuditTrailClientReadOnly.createWithPackageOverrides( | ||||||
| iotaClient, | ||||||
| new auditTrail.PackageOverrides(IOTA_AUDIT_TRAIL_PKG_ID, IOTA_TF_COMPONENTS_PKG_ID), | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| // Well-known networks have well-known notarization package id | ||||||
| if (regularNetworks.has(network as Network)) { | ||||||
| return await auditTrail.AuditTrailClientReadOnly.create(iotaClient); | ||||||
| } | ||||||
|
|
||||||
| throw new Error( | ||||||
| 'Failed to create a AuditTrailClientReadOnly; declare IOTA_AUDIT_TRAIL_PKG_ID and IOTA_TF_COMPONENTS_PKG_ID environment if running on a custom network.', | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit 🙏
Suggested change
|
||||||
| ); | ||||||
| }; | ||||||
|
|
||||||
| export async function tryDIDParse(didCandidate: string): Promise<identity.IotaDID | null> { | ||||||
| try { | ||||||
| await initIdentityWasmWeb(); | ||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VITE_IOTA_AUDIT_TRAIL_PKG_IDandVITE_IOTA_TF_COMPONENTS_PKG_IDshouldnt be in the.env.example¿