Skip to content

Commit 579aff0

Browse files
committed
feat: re-enable IPFS validation for registry scripts
1 parent e2fa257 commit 579aff0

File tree

6 files changed

+31
-24
lines changed

6 files changed

+31
-24
lines changed

javascript/engine-js/src/Engine.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ export class TokenScriptEngine {
134134

135135
const resolveResult = await this.repo.getTokenScript(sourceId, forceRefresh);
136136

137-
return await this.initializeTokenScriptObject(resolveResult.xml, resolveResult.type, resolveResult.sourceId, resolveResult.sourceUrl, resolveResult, viewBinding);
137+
const {xml, ...sourceInfo} = resolveResult;
138+
139+
return await this.initializeTokenScriptObject(resolveResult.xml, resolveResult.type, resolveResult.sourceId, resolveResult.sourceUrl, sourceInfo, viewBinding);
138140
}
139141

140142
/**

javascript/engine-js/src/security/SecurityInfo.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ export class SecurityInfo {
8585
this.originStatuses[name] = originStatus;
8686
}
8787

88+
// TODO: Show third party message when in warning state
89+
8890
if (originFailCount === 0){
8991
this.securityInfo.status = SecurityStatus.VALID;
9092
this.securityInfo.statusText = this.securityInfo.trustedKey ? "The TokenScript is signed by a trusted key" : "The TokenScript is authenticated for use with all specified token origins.";

javascript/engine-js/src/tokenScript/Origin.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,13 @@ export class Origin {
204204
const scriptSource = this.tokenScript.getSourceInfo();
205205
const [chain, contractAddress] = (scriptSource.tsId ?? "").split("-");
206206

207+
console.log("Script Info ", scriptSource.scriptInfo);
208+
207209
// The same script Cid should be specified for all addresses in the same contract scriptUri in order to be valid
208210
const addresses = contract.getAddresses();
209211

212+
let authenticated: boolean = null;
213+
210214
for (const i in addresses){
211215

212216
const address = addresses[i];
@@ -215,14 +219,12 @@ export class Origin {
215219

216220
if (
217221
contractAddress &&
218-
scriptSource.source === "scriptUri" &&
219-
address.address === contractAddress &&
222+
address.address.toLowerCase() === contractAddress.toLowerCase() &&
220223
address.chain === parseInt(chain)
221224
){
222225
scriptUri = scriptSource.sourceUrl;
223226
} else {
224227
// We could fetch the scriptURI of the contract and compare the IPFS hash, but for the moment this seems like overkill and is slow
225-
return;
226228
/*try {
227229
scriptUri = await this.tokenScript.getEngine().getScriptUri(address.chain, address.address);
228230
} catch (e) {
@@ -232,6 +234,10 @@ export class Origin {
232234
// JB: Yes.
233235
}
234236

237+
if (authenticated !== false){
238+
authenticated = scriptSource.source === ScriptSourceType.SCRIPT_URI || scriptSource.scriptInfo?.authenticated;
239+
}
240+
235241
console.log("IPFS Validator: checking source URL ", scriptUri);
236242

237243
if (!scriptUri) {
@@ -254,8 +260,14 @@ export class Origin {
254260

255261
this.securityStatus = {
256262
type: AuthenticationType.IPFS_CID,
257-
status: SecurityStatus.VALID,
258-
statusText: "The TokenScript IPFS CID matches the scriptURI specified by the contract"
263+
status: authenticated ? SecurityStatus.VALID : SecurityStatus.WARNING,
264+
statusText:
265+
(authenticated ?
266+
"This TokenScript has been set by the contract owner" :
267+
"This is a third party TokenScript, please sign any transaction with care") + "\n" +
268+
(scriptSource.source === ScriptSourceType.SCRIPT_URI ?
269+
"The IPFS CID matches the scriptURI specified by the contract" :
270+
"The IPFS CID matches the scriptURI specified by the registry")
259271
}
260272
}
261273
}

javascript/tokenscript-viewer/src/components.d.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { JSX } from "@stencil/core";
1414
import { TokenScript as TokenScript1 } from "@tokenscript/engine-js/src/TokenScript";
1515
import { IntegrationViewer } from "./components/viewers/integration/integration-viewer";
1616
import { ITxValidationInfo } from "../../engine-js/src/security/TransactionValidator";
17-
import { TokenScript as TokenScript2 } from "@tokenscript/engine-js/dist/lib.esm/TokenScript";
1817
import { ScriptInfo } from "@tokenscript/engine-js/src/repo/sources/SourceInterface";
1918
import { Card } from "@tokenscript/engine-js/src/tokenScript/Card";
2019
import { TabbedViewer } from "./components/viewers/tabbed/tabbed-viewer";
@@ -30,7 +29,6 @@ export { JSX } from "@stencil/core";
3029
export { TokenScript as TokenScript1 } from "@tokenscript/engine-js/src/TokenScript";
3130
export { IntegrationViewer } from "./components/viewers/integration/integration-viewer";
3231
export { ITxValidationInfo } from "../../engine-js/src/security/TransactionValidator";
33-
export { TokenScript as TokenScript2 } from "@tokenscript/engine-js/dist/lib.esm/TokenScript";
3432
export { ScriptInfo } from "@tokenscript/engine-js/src/repo/sources/SourceInterface";
3533
export { Card } from "@tokenscript/engine-js/src/tokenScript/Card";
3634
export { TabbedViewer } from "./components/viewers/tabbed/tabbed-viewer";
@@ -108,9 +106,6 @@ export namespace Components {
108106
interface OpenseaViewer {
109107
"app": AppRoot;
110108
}
111-
interface OtherTappsButton {
112-
"tokenScript": TokenScript2;
113-
}
114109
interface PopoverDialog {
115110
"closeDialog": () => Promise<void>;
116111
"dialogClasses": string[];
@@ -490,12 +485,6 @@ declare global {
490485
prototype: HTMLOpenseaViewerElement;
491486
new (): HTMLOpenseaViewerElement;
492487
};
493-
interface HTMLOtherTappsButtonElement extends Components.OtherTappsButton, HTMLStencilElement {
494-
}
495-
var HTMLOtherTappsButtonElement: {
496-
prototype: HTMLOtherTappsButtonElement;
497-
new (): HTMLOtherTappsButtonElement;
498-
};
499488
interface HTMLPopoverDialogElement extends Components.PopoverDialog, HTMLStencilElement {
500489
}
501490
var HTMLPopoverDialogElement: {
@@ -760,7 +749,6 @@ declare global {
760749
"mooar-viewer": HTMLMooarViewerElement;
761750
"new-viewer": HTMLNewViewerElement;
762751
"opensea-viewer": HTMLOpenseaViewerElement;
763-
"other-tapps-button": HTMLOtherTappsButtonElement;
764752
"popover-dialog": HTMLPopoverDialogElement;
765753
"script-select-dialog": HTMLScriptSelectDialogElement;
766754
"security-status": HTMLSecurityStatusElement;
@@ -867,9 +855,6 @@ declare namespace LocalJSX {
867855
"onShowLoader"?: (event: OpenseaViewerCustomEvent<void>) => void;
868856
"onShowToast"?: (event: OpenseaViewerCustomEvent<ShowToastEventArgs>) => void;
869857
}
870-
interface OtherTappsButton {
871-
"tokenScript"?: TokenScript2;
872-
}
873858
interface PopoverDialog {
874859
"dialogClasses"?: string[];
875860
"dialogStyles"?: {[cssProp: string]: string};
@@ -1016,7 +1001,6 @@ declare namespace LocalJSX {
10161001
"mooar-viewer": MooarViewer;
10171002
"new-viewer": NewViewer;
10181003
"opensea-viewer": OpenseaViewer;
1019-
"other-tapps-button": OtherTappsButton;
10201004
"popover-dialog": PopoverDialog;
10211005
"script-select-dialog": ScriptSelectDialog;
10221006
"security-status": SecurityStatus;
@@ -1068,7 +1052,6 @@ declare module "@stencil/core" {
10681052
"mooar-viewer": LocalJSX.MooarViewer & JSXBase.HTMLAttributes<HTMLMooarViewerElement>;
10691053
"new-viewer": LocalJSX.NewViewer & JSXBase.HTMLAttributes<HTMLNewViewerElement>;
10701054
"opensea-viewer": LocalJSX.OpenseaViewer & JSXBase.HTMLAttributes<HTMLOpenseaViewerElement>;
1071-
"other-tapps-button": LocalJSX.OtherTappsButton & JSXBase.HTMLAttributes<HTMLOtherTappsButtonElement>;
10721055
"popover-dialog": LocalJSX.PopoverDialog & JSXBase.HTMLAttributes<HTMLPopoverDialogElement>;
10731056
"script-select-dialog": LocalJSX.ScriptSelectDialog & JSXBase.HTMLAttributes<HTMLScriptSelectDialogElement>;
10741057
"security-status": LocalJSX.SecurityStatus & JSXBase.HTMLAttributes<HTMLSecurityStatusElement>;

javascript/tokenscript-viewer/src/components/common/tokens-grid/token-security-status-popover.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export class TokenSecurityStatus {
2929
this.statusColor = "#3bd23b";
3030
this.statusIcon = "✔";
3131
break;
32+
case TSSecurityStatus.WARNING:
33+
this.statusColor = "#ff871d";
34+
this.statusIcon = "✔";
35+
break;
3236
case TSSecurityStatus.INVALID:
3337
default:
3438
this.statusColor = "#ff4f4f";
@@ -48,7 +52,7 @@ export class TokenSecurityStatus {
4852
<Host>
4953
<popover-dialog ref={(el) => this.dialog = el as HTMLPopoverDialogElement} dialogStyles={{background: "#fff !important", color: "#000 !important"}}>
5054
<h1 class="security-popover-icon" style={{color: this.statusColor}}>{this.statusIcon}</h1>
51-
<strong>{this.securityInfo.statusText}</strong>
55+
<strong innerHTML={this.securityInfo.statusText.replaceAll("\n", "<br/>")}/>
5256
<p style={{wordWrap: "break-word"}} innerHTML={this.getDetailedSecurityInfo().replaceAll("\n", "<br/>")}>
5357
</p>
5458
</popover-dialog>

javascript/tokenscript-viewer/src/components/common/tokens-grid/token-security-status.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export class TokenSecurityStatus {
3030
this.statusColor = "#3bd23b";
3131
this.statusIcon = "✔";
3232
break;
33+
case TSSecurityStatus.WARNING:
34+
this.statusColor = "#ff871d";
35+
this.statusIcon = "✔";
36+
break;
3337
case TSSecurityStatus.INVALID:
3438
default:
3539
this.statusColor = "#ff4f4f";

0 commit comments

Comments
 (0)