From 402175edd60ee1499d07e5bb3be1e1841d9215f2 Mon Sep 17 00:00:00 2001 From: Arie Trouw Date: Tue, 27 Jun 2023 17:14:24 -0700 Subject: [PATCH] manifest now has wallet support --- packages/manifest/src/ManifestWrapper.ts | 5 +++-- packages/manifest/src/Payload.ts | 1 + packages/manifest/src/schema.json | 4 ++++ packages/manifest/src/spec/Manifest.spec.ts | 9 +++++++-- .../manifest/src/spec/simple-node-indirect-manifest.json | 3 +++ .../manifest/src/spec/simple-node-inline-manifest.json | 3 +++ 6 files changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/manifest/src/ManifestWrapper.ts b/packages/manifest/src/ManifestWrapper.ts index 3d9cff41823..792c7c1fdb9 100644 --- a/packages/manifest/src/ManifestWrapper.ts +++ b/packages/manifest/src/ManifestWrapper.ts @@ -2,12 +2,13 @@ import { assertEx } from '@xylabs/assert' import { CreatableModuleDictionary } from '@xyo-network/module' import { MemoryNode, NodeWrapper } from '@xyo-network/node' import { PayloadWrapper } from '@xyo-network/payload-wrapper' +import { WalletInstance } from '@xyo-network/wallet-model' import { standardCreatableModules } from './ModuleFactory' import { DappManifest, ManifestPayload, ModuleManifest } from './Payload' export class ManifestWrapper extends PayloadWrapper { - constructor(payload: ManifestPayload) { + constructor(payload: ManifestPayload, protected wallet: WalletInstance) { super(payload) } @@ -80,7 +81,7 @@ export class ManifestWrapper extends PayloadWrapper { `No module with [${manifest.id}] id available for registration`, ) - const module = await creatableModule.create(manifest.config ? { config: manifest.config } : undefined) + const module = await creatableModule.create(manifest.config ? { account: this.wallet, config: manifest.config } : undefined) await node.module.register(module) return module } diff --git a/packages/manifest/src/Payload.ts b/packages/manifest/src/Payload.ts index 4e3a5969139..ef5a7c2c72b 100644 --- a/packages/manifest/src/Payload.ts +++ b/packages/manifest/src/Payload.ts @@ -18,6 +18,7 @@ export interface DappManifest extends Manifest { } export interface ModuleManifest extends Manifest { + accountPath?: string config?: ModuleConfig features?: string[] language?: string diff --git a/packages/manifest/src/schema.json b/packages/manifest/src/schema.json index ac82adc8873..79cff0afe8b 100644 --- a/packages/manifest/src/schema.json +++ b/packages/manifest/src/schema.json @@ -89,6 +89,10 @@ "additionalProperties": false, "description": "Module Definition", "properties": { + "accountPath": { + "description": "HDWallet path to derive account", + "type": "string" + }, "architecture": { "description": "Architecture", "enum": [ diff --git a/packages/manifest/src/spec/Manifest.spec.ts b/packages/manifest/src/spec/Manifest.spec.ts index 55768cb7989..683912d9a1c 100644 --- a/packages/manifest/src/spec/Manifest.spec.ts +++ b/packages/manifest/src/spec/Manifest.spec.ts @@ -1,3 +1,4 @@ +import { HDWallet } from '@xyo-network/account' import { AddressSchema } from '@xyo-network/address-payload-plugin' import { NodeWrapper } from '@xyo-network/node' @@ -9,7 +10,9 @@ import simpleNodeInlineManifest from './simple-node-inline-manifest.json' describe('Manifest', () => { describe('Create Node from Manifest', () => { test('Simple Node [Indirect]', async () => { - const manifest = new ManifestWrapper(simpleNodeIndirectManifest as ManifestPayload) + const mnemonic = 'later puppy sound rebuild rebuild noise ozone amazing hope broccoli crystal grief' + const wallet = await HDWallet.fromMnemonic(mnemonic) + const manifest = new ManifestWrapper(simpleNodeIndirectManifest as ManifestPayload, wallet) const [node] = await manifest.loadDapps() expect(node).toBeDefined() const wrapper = NodeWrapper.wrap(node) @@ -19,7 +22,9 @@ describe('Manifest', () => { expect(await node.downResolver.resolve()).toBeArrayOfSize(3) }) test('Simple Node [Inline]', async () => { - const manifest = new ManifestWrapper(simpleNodeInlineManifest as ManifestPayload) + const mnemonic = 'later puppy sound rebuild rebuild noise ozone amazing hope broccoli crystal grief' + const wallet = await HDWallet.fromMnemonic(mnemonic) + const manifest = new ManifestWrapper(simpleNodeInlineManifest as ManifestPayload, wallet) const [node] = await manifest.loadDapps() expect(node).toBeDefined() const wrapper = NodeWrapper.wrap(node) diff --git a/packages/manifest/src/spec/simple-node-indirect-manifest.json b/packages/manifest/src/spec/simple-node-indirect-manifest.json index b477e90f819..adef9052a9a 100644 --- a/packages/manifest/src/spec/simple-node-indirect-manifest.json +++ b/packages/manifest/src/spec/simple-node-indirect-manifest.json @@ -22,14 +22,17 @@ ], "modules": { "ScratchArchivist": { + "accountPath": "1'", "id": "network.xyo.archivist", "language": "javascript" }, "SimpleArchivist": { + "accountPath": "2'", "id": "network.xyo.archivist", "language": "javascript" }, "SimpleSentinel": { + "accountPath": "3'", "id": "network.xyo.sentinel", "language": "javascript" } diff --git a/packages/manifest/src/spec/simple-node-inline-manifest.json b/packages/manifest/src/spec/simple-node-inline-manifest.json index 0d8fa4bf0e2..212a00bf1be 100644 --- a/packages/manifest/src/spec/simple-node-inline-manifest.json +++ b/packages/manifest/src/spec/simple-node-inline-manifest.json @@ -5,6 +5,7 @@ "modules": { "private": [ { + "accountPath": "1'", "id": "network.xyo.archivist", "language": "javascript", "name": "ScratchArchivist" @@ -12,11 +13,13 @@ ], "public": [ { + "accountPath": "2'", "id": "network.xyo.archivist", "language": "javascript", "name": "SimpleArchivist" }, { + "accountPath": "3'", "id": "network.xyo.sentinel", "language": "javascript", "name": "SimpleSentinel"