From bf00e08a63f38018a04931165aa0dc9c488fb819 Mon Sep 17 00:00:00 2001 From: Arie Trouw Date: Tue, 10 Oct 2023 16:12:37 -0700 Subject: [PATCH] sourceQuery for BW --- package.json | 3 +- .../packages/archivist/src/lib/validByType.ts | 4 +-- .../abstract/src/AbstractArchivist.ts | 4 +-- .../packages/abstract/src/AbstractBridge.ts | 3 +- .../bridge/packages/http/src/HttpBridge.ts | 2 +- .../bridge/packages/model/src/Bridge.ts | 2 +- .../module-resolver/src/ProxyModule.ts | 2 +- .../packages/worker/src/WorkerBridge.ts | 2 +- .../packages/wrapper/src/BridgeWrapper.ts | 2 +- .../packages/abstract/src/AbstractDiviner.ts | 3 +- .../packages/abstract/src/AbstractModule.ts | 29 ++++++------------- .../src/QueryValidator/QueryValidator.ts | 2 +- .../QueryValidator/SupportedQueryValidator.ts | 3 +- .../packages/abstract/src/determineAccount.ts | 27 +++++++++++++++++ .../model/src/EventsModels/ModuleQueried.ts | 2 +- .../packages/model/src/module/ModuleFields.ts | 2 +- .../packages/wrapper/src/ModuleWrapper.ts | 3 +- .../packages/abstract/src/AbstractNode.ts | 3 +- .../packages/sentinel/src/AbstractSentinel.ts | 4 +-- .../packages/abstract/src/AbstractWitness.ts | 3 +- .../src/routes/address/post/getQueryConfig.ts | 3 +- .../routes/src/routes/address/post/post.ts | 2 +- .../test/src/routes/node/node.spec.ts | 4 +-- .../packages/ethers/src/spec/Witness.spec.ts | 1 + .../src/Witness/spec/Witness.data.spec.ts | 4 +++ .../src/Witness/spec/Witness.https.spec.ts | 4 +++ .../src/Witness/spec/Witness.ipfs.spec.ts | 4 +++ .../src/Witness/spec/Witness.sentinel.spec.ts | 4 +++ .../src/Witness/spec/Witness.spec.ts | 4 +++ .../src/Witness/spec/Witness.video.spec.ts | 4 +++ .../packages/builder/src/Builder.ts | 10 +++++++ .../src/Query/QueryBoundWitnessBuilder.ts | 11 ++----- .../src/Query/QueryBoundWitnessValidator.ts | 2 +- .../src/Query/QueryBoundWitnessWrapper.ts | 17 +---------- .../packages/builder/src/Query/index.ts | 2 -- .../{models => BoundWitness}/BoundWitness.ts | 7 +++-- .../BoundWitnessJsonSchema.ts | 0 .../BoundWitnessSchema.ts | 0 .../src/{models => BoundWitness}/index.ts | 0 .../Query => model/src}/QueryBoundWitness.ts | 6 ++-- .../boundwitness/packages/model/src/index.ts | 5 ++-- .../packages/model/src/isBoundWitness.ts | 9 ++++++ .../model/src/isBoundWitnessPayload.ts | 5 ---- .../boundwitness/packages/model/tsconfig.json | 1 - .../model/src/isPayloadOfSchemaType.ts | 4 +++ .../packages/payloadset-plugin/src/Plugin.ts | 3 +- .../payloadset-plugin/src/Resolver.ts | 3 +- 47 files changed, 135 insertions(+), 89 deletions(-) create mode 100644 packages/modules/packages/module/packages/abstract/src/determineAccount.ts rename packages/protocol/packages/boundwitness/packages/model/src/{models => BoundWitness}/BoundWitness.ts (66%) rename packages/protocol/packages/boundwitness/packages/model/src/{models => BoundWitness}/BoundWitnessJsonSchema.ts (100%) rename packages/protocol/packages/boundwitness/packages/model/src/{models => BoundWitness}/BoundWitnessSchema.ts (100%) rename packages/protocol/packages/boundwitness/packages/model/src/{models => BoundWitness}/index.ts (100%) rename packages/protocol/packages/boundwitness/packages/{builder/src/Query => model/src}/QueryBoundWitness.ts (74%) create mode 100644 packages/protocol/packages/boundwitness/packages/model/src/isBoundWitness.ts delete mode 100644 packages/protocol/packages/boundwitness/packages/model/src/isBoundWitnessPayload.ts diff --git a/package.json b/package.json index e25b84f924a..c75a31b1aab 100644 --- a/package.json +++ b/package.json @@ -108,6 +108,7 @@ "test-esm": "node $(yarn jest --no-cache --forceExit)", "test": "jest --no-cache --forceExit", "test:no-slow": "jest . --passWithNoTests --forceExit -- --group=-slow", + "test:thumbnail": "jest . --passWithNoTests --forceExit -- --group=thumbnail", "test:no-mongo": "jest . --passWithNoTests --forceExit -c ./jest.config.no-mongo.ts -- --group=-mongo", "test:ci": "jest --runInBand --coverage --forceExit --passWithNoTests", "xyo": "node ./packages/cli/dist/cjs/index.js", @@ -125,4 +126,4 @@ "yarn": "1.22.19" }, "type": "module" -} +} \ No newline at end of file diff --git a/packages/modules-mongo/packages/archivist/src/lib/validByType.ts b/packages/modules-mongo/packages/archivist/src/lib/validByType.ts index e2a56a66d8b..15e0aef61b4 100644 --- a/packages/modules-mongo/packages/archivist/src/lib/validByType.ts +++ b/packages/modules-mongo/packages/archivist/src/lib/validByType.ts @@ -1,5 +1,5 @@ -import { isQueryBoundWitness, QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder' -import { isBoundWitness } from '@xyo-network/boundwitness-model' +import { QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder' +import { isBoundWitness, isQueryBoundWitness } from '@xyo-network/boundwitness-model' import { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper' import { Payload } from '@xyo-network/payload-model' import { PayloadWrapper } from '@xyo-network/payload-wrapper' diff --git a/packages/modules/packages/archivist/packages/abstract/src/AbstractArchivist.ts b/packages/modules/packages/archivist/packages/abstract/src/AbstractArchivist.ts index 36076c14e8d..9d6a908b2fb 100644 --- a/packages/modules/packages/archivist/packages/abstract/src/AbstractArchivist.ts +++ b/packages/modules/packages/archivist/packages/abstract/src/AbstractArchivist.ts @@ -16,8 +16,8 @@ import { asArchivistInstance, isArchivistInstance, } from '@xyo-network/archivist-model' -import { QueryBoundWitness, QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder' -import { BoundWitness, BoundWitnessSchema } from '@xyo-network/boundwitness-model' +import { QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder' +import { BoundWitness, BoundWitnessSchema, QueryBoundWitness } from '@xyo-network/boundwitness-model' import { PayloadHasher } from '@xyo-network/core' import { AbstractModuleInstance } from '@xyo-network/module-abstract' import { duplicateModules, ModuleConfig, ModuleQueryHandlerResult } from '@xyo-network/module-model' diff --git a/packages/modules/packages/bridge/packages/abstract/src/AbstractBridge.ts b/packages/modules/packages/bridge/packages/abstract/src/AbstractBridge.ts index d4d28f201e1..825e82e20e6 100644 --- a/packages/modules/packages/bridge/packages/abstract/src/AbstractBridge.ts +++ b/packages/modules/packages/bridge/packages/abstract/src/AbstractBridge.ts @@ -1,4 +1,5 @@ -import { QueryBoundWitness, QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitness } from '@xyo-network/boundwitness-model' import { BridgeConfigSchema, BridgeConnectedQuerySchema, diff --git a/packages/modules/packages/bridge/packages/http/src/HttpBridge.ts b/packages/modules/packages/bridge/packages/http/src/HttpBridge.ts index 261a6d07e26..1d327b89b7d 100644 --- a/packages/modules/packages/bridge/packages/http/src/HttpBridge.ts +++ b/packages/modules/packages/bridge/packages/http/src/HttpBridge.ts @@ -3,7 +3,7 @@ import { compact } from '@xylabs/lodash' import { AbstractBridge } from '@xyo-network/abstract-bridge' import { ApiEnvelope } from '@xyo-network/api-models' import { AxiosError, AxiosJson } from '@xyo-network/axios' -import { QueryBoundWitness } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitness } from '@xyo-network/boundwitness-model' import { BridgeModule, CacheConfig } from '@xyo-network/bridge-model' import { ConfigPayload, ConfigSchema } from '@xyo-network/config-payload-plugin' import { ManifestPayload, ManifestPayloadSchema } from '@xyo-network/manifest-model' diff --git a/packages/modules/packages/bridge/packages/model/src/Bridge.ts b/packages/modules/packages/bridge/packages/model/src/Bridge.ts index 7a13286e1f1..a35c9063f8c 100644 --- a/packages/modules/packages/bridge/packages/model/src/Bridge.ts +++ b/packages/modules/packages/bridge/packages/model/src/Bridge.ts @@ -1,4 +1,4 @@ -import { QueryBoundWitness } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitness } from '@xyo-network/boundwitness-model' import { ManifestPayload } from '@xyo-network/manifest-model' import { AnyConfigSchema, diff --git a/packages/modules/packages/bridge/packages/module-resolver/src/ProxyModule.ts b/packages/modules/packages/bridge/packages/module-resolver/src/ProxyModule.ts index 4504688c11b..4d5c58536ac 100644 --- a/packages/modules/packages/bridge/packages/module-resolver/src/ProxyModule.ts +++ b/packages/modules/packages/bridge/packages/module-resolver/src/ProxyModule.ts @@ -1,7 +1,7 @@ import { assertEx } from '@xylabs/assert' import { compact } from '@xylabs/lodash' import { AddressPayload, AddressSchema } from '@xyo-network/address-payload-plugin' -import { QueryBoundWitness } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitness } from '@xyo-network/boundwitness-model' import { BridgeModule } from '@xyo-network/bridge-model' import { ManifestPayloadSchema, ModuleManifestPayload } from '@xyo-network/manifest-model' import { BaseEmitter } from '@xyo-network/module-abstract' diff --git a/packages/modules/packages/bridge/packages/worker/src/WorkerBridge.ts b/packages/modules/packages/bridge/packages/worker/src/WorkerBridge.ts index ed9958e96ba..179b1d6aff5 100644 --- a/packages/modules/packages/bridge/packages/worker/src/WorkerBridge.ts +++ b/packages/modules/packages/bridge/packages/worker/src/WorkerBridge.ts @@ -2,7 +2,7 @@ import { assertEx } from '@xylabs/assert' import { delay } from '@xylabs/delay' import { compact } from '@xylabs/lodash' import { AbstractBridge } from '@xyo-network/abstract-bridge' -import { QueryBoundWitness } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitness } from '@xyo-network/boundwitness-model' import { BridgeModule, CacheConfig } from '@xyo-network/bridge-model' import { ConfigPayload, ConfigSchema } from '@xyo-network/config-payload-plugin' import { ManifestPayload, ManifestPayloadSchema } from '@xyo-network/manifest-model' diff --git a/packages/modules/packages/bridge/packages/wrapper/src/BridgeWrapper.ts b/packages/modules/packages/bridge/packages/wrapper/src/BridgeWrapper.ts index f89cc902c56..03edd443577 100644 --- a/packages/modules/packages/bridge/packages/wrapper/src/BridgeWrapper.ts +++ b/packages/modules/packages/bridge/packages/wrapper/src/BridgeWrapper.ts @@ -1,5 +1,5 @@ import { assertEx } from '@xylabs/assert' -import { QueryBoundWitness } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitness } from '@xyo-network/boundwitness-model' import { BridgeConnectQuerySchema, BridgeDisconnectQuerySchema, diff --git a/packages/modules/packages/diviner/packages/abstract/src/AbstractDiviner.ts b/packages/modules/packages/diviner/packages/abstract/src/AbstractDiviner.ts index 32fba056e85..81b796080a8 100644 --- a/packages/modules/packages/diviner/packages/abstract/src/AbstractDiviner.ts +++ b/packages/modules/packages/diviner/packages/abstract/src/AbstractDiviner.ts @@ -1,5 +1,6 @@ import { assertEx } from '@xylabs/assert' -import { QueryBoundWitness, QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitness } from '@xyo-network/boundwitness-model' import { PayloadHasher } from '@xyo-network/core' import { CustomDivinerModule, diff --git a/packages/modules/packages/module/packages/abstract/src/AbstractModule.ts b/packages/modules/packages/module/packages/abstract/src/AbstractModule.ts index e74e8c49075..ffe72e67fb0 100644 --- a/packages/modules/packages/module/packages/abstract/src/AbstractModule.ts +++ b/packages/modules/packages/module/packages/abstract/src/AbstractModule.ts @@ -6,8 +6,8 @@ import { HDWallet } from '@xyo-network/account' import { AccountInstance } from '@xyo-network/account-model' import { AddressPayload, AddressSchema } from '@xyo-network/address-payload-plugin' import { ArchivistInstance, asArchivistInstance } from '@xyo-network/archivist-model' -import { BoundWitnessBuilder, QueryBoundWitness, QueryBoundWitnessBuilder, QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder' -import { BoundWitness } from '@xyo-network/boundwitness-model' +import { BoundWitnessBuilder, QueryBoundWitnessBuilder, QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder' +import { BoundWitness, QueryBoundWitness } from '@xyo-network/boundwitness-model' import { ConfigPayload, ConfigSchema } from '@xyo-network/config-payload-plugin' import { PayloadHasher } from '@xyo-network/core' import { handleError, handleErrorAsync } from '@xyo-network/error' @@ -52,6 +52,7 @@ import { IdLogger } from '@xyo-network/shared' import { WalletInstance } from '@xyo-network/wallet-model' import { BaseEmitter } from './BaseEmitter' +import { determineAccount } from './determineAccount' import { ModuleErrorBuilder } from './Error' import { ModuleConfigQueryValidator, Queryable, SupportedQueryValidator } from './QueryValidator' @@ -203,26 +204,12 @@ export abstract class AbstractModule { - if (wallet) { - return assertEx(accountDerivationPath ? await wallet.derivePath(accountDerivationPath) : wallet, 'Failed to derive account from path') - } else if (account === 'random') { - return await HDWallet.random() - } else if (account) { - return account - } else { - //this should eventually be removed/thrown - console.warn('AbstractModule.determineAccount: No account provided - Creating Random account') - return await HDWallet.random() - } + return await determineAccount(params) } static factory( @@ -285,6 +272,7 @@ export abstract class AbstractModule { this._noOverride('query') + const sourceQuery = await PayloadHasher.hashAsync(query) return await this.busy(async () => { const resultPayloads: Payload[] = [] const errorPayloads: ModuleError[] = [] @@ -313,7 +301,7 @@ export abstract class AbstractModule( query: T, payloads: Payload[], + sourceQuery?: string, additionalWitnesses: AccountInstance[] = [], errors?: ModuleError[], ): Promise { - const builder = new BoundWitnessBuilder().payloads(payloads).errors(errors) + const builder = new BoundWitnessBuilder().payloads(payloads).errors(errors).sourceQuery(sourceQuery) const queryWitnessAccount = this.queryAccounts[query.schema as ModuleQueryBase['schema']] const witnesses = [this.account, queryWitnessAccount, ...additionalWitnesses].filter(exists) builder.witnesses(witnesses) diff --git a/packages/modules/packages/module/packages/abstract/src/QueryValidator/QueryValidator.ts b/packages/modules/packages/module/packages/abstract/src/QueryValidator/QueryValidator.ts index 958cb68e069..c0f5e454ff1 100644 --- a/packages/modules/packages/module/packages/abstract/src/QueryValidator/QueryValidator.ts +++ b/packages/modules/packages/module/packages/abstract/src/QueryValidator/QueryValidator.ts @@ -1,4 +1,4 @@ -import { QueryBoundWitness } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitness } from '@xyo-network/boundwitness-model' import { Payload } from '@xyo-network/payload-model' import { Promisable } from '@xyo-network/promise' diff --git a/packages/modules/packages/module/packages/abstract/src/QueryValidator/SupportedQueryValidator.ts b/packages/modules/packages/module/packages/abstract/src/QueryValidator/SupportedQueryValidator.ts index 018d7f8113e..e82fae444c5 100644 --- a/packages/modules/packages/module/packages/abstract/src/QueryValidator/SupportedQueryValidator.ts +++ b/packages/modules/packages/module/packages/abstract/src/QueryValidator/SupportedQueryValidator.ts @@ -1,4 +1,5 @@ -import { QueryBoundWitness, QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitness } from '@xyo-network/boundwitness-model' import { Module, ModuleQuery } from '@xyo-network/module-model' import { Payload } from '@xyo-network/payload-model' diff --git a/packages/modules/packages/module/packages/abstract/src/determineAccount.ts b/packages/modules/packages/module/packages/abstract/src/determineAccount.ts new file mode 100644 index 00000000000..f0235bb5feb --- /dev/null +++ b/packages/modules/packages/module/packages/abstract/src/determineAccount.ts @@ -0,0 +1,27 @@ +/* eslint-disable max-lines */ +import { assertEx } from '@xylabs/assert' +import { HDWallet } from '@xyo-network/account' +import { AccountInstance } from '@xyo-network/account-model' +import { WalletInstance } from '@xyo-network/wallet-model' + +export const determineAccount = async ({ + account, + accountDerivationPath, + wallet, +}: { + account?: AccountInstance | 'random' + accountDerivationPath?: string + wallet?: WalletInstance +}): Promise => { + if (wallet) { + return assertEx(accountDerivationPath ? await wallet.derivePath(accountDerivationPath) : wallet, 'Failed to derive account from path') + } else if (account === 'random') { + return await HDWallet.random() + } else if (account) { + return account + } else { + //this should eventually be removed/thrown + console.warn('AbstractModule.determineAccount: No account provided - Creating Random account') + return await HDWallet.random() + } +} diff --git a/packages/modules/packages/module/packages/model/src/EventsModels/ModuleQueried.ts b/packages/modules/packages/module/packages/model/src/EventsModels/ModuleQueried.ts index ed23ae89547..d4b3f783a1f 100644 --- a/packages/modules/packages/module/packages/model/src/EventsModels/ModuleQueried.ts +++ b/packages/modules/packages/module/packages/model/src/EventsModels/ModuleQueried.ts @@ -1,4 +1,4 @@ -import { QueryBoundWitness } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitness } from '@xyo-network/boundwitness-model' import { EventData } from '@xyo-network/module-events' import { Payload } from '@xyo-network/payload-model' diff --git a/packages/modules/packages/module/packages/model/src/module/ModuleFields.ts b/packages/modules/packages/module/packages/model/src/module/ModuleFields.ts index 7f3a0298dac..e9622da4d37 100644 --- a/packages/modules/packages/module/packages/model/src/module/ModuleFields.ts +++ b/packages/modules/packages/module/packages/model/src/module/ModuleFields.ts @@ -1,4 +1,4 @@ -import { QueryBoundWitness } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitness } from '@xyo-network/boundwitness-model' import { Payload } from '@xyo-network/payload-model' import { Promisable } from '@xyo-network/promise' diff --git a/packages/modules/packages/module/packages/wrapper/src/ModuleWrapper.ts b/packages/modules/packages/module/packages/wrapper/src/ModuleWrapper.ts index e22877893a6..5f76f9c7876 100644 --- a/packages/modules/packages/module/packages/wrapper/src/ModuleWrapper.ts +++ b/packages/modules/packages/module/packages/wrapper/src/ModuleWrapper.ts @@ -2,7 +2,8 @@ import { assertEx } from '@xylabs/assert' import { compact } from '@xylabs/lodash' import { Account } from '@xyo-network/account' import { AccountInstance } from '@xyo-network/account-model' -import { QueryBoundWitness, QueryBoundWitnessBuilder } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitnessBuilder } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitness } from '@xyo-network/boundwitness-model' import { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper' import { Base } from '@xyo-network/core' import { ModuleManifestPayload } from '@xyo-network/manifest-model' diff --git a/packages/modules/packages/node/packages/abstract/src/AbstractNode.ts b/packages/modules/packages/node/packages/abstract/src/AbstractNode.ts index c3295fa31e8..b9e4a3b48b2 100644 --- a/packages/modules/packages/node/packages/abstract/src/AbstractNode.ts +++ b/packages/modules/packages/node/packages/abstract/src/AbstractNode.ts @@ -1,6 +1,7 @@ import { assertEx } from '@xylabs/assert' import { AddressPayload, AddressSchema } from '@xyo-network/address-payload-plugin' -import { QueryBoundWitness, QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitness } from '@xyo-network/boundwitness-model' import { NodeManifestPayload, NodeManifestPayloadSchema } from '@xyo-network/manifest-model' import { AbstractModuleInstance } from '@xyo-network/module-abstract' import { diff --git a/packages/modules/packages/sentinel/src/AbstractSentinel.ts b/packages/modules/packages/sentinel/src/AbstractSentinel.ts index f00f7535547..8deba82c985 100644 --- a/packages/modules/packages/sentinel/src/AbstractSentinel.ts +++ b/packages/modules/packages/sentinel/src/AbstractSentinel.ts @@ -1,7 +1,7 @@ import { assertEx } from '@xylabs/assert' import { uniq } from '@xylabs/lodash' -import { QueryBoundWitness, QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder' -import { BoundWitness, isBoundWitness, notBoundWitness } from '@xyo-network/boundwitness-model' +import { QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder' +import { BoundWitness, isBoundWitness, notBoundWitness, QueryBoundWitness } from '@xyo-network/boundwitness-model' import { AbstractModuleInstance } from '@xyo-network/module-abstract' import { ModuleConfig, ModuleQueryHandlerResult } from '@xyo-network/module-model' import { Payload } from '@xyo-network/payload-model' diff --git a/packages/modules/packages/witness/packages/abstract/src/AbstractWitness.ts b/packages/modules/packages/witness/packages/abstract/src/AbstractWitness.ts index e8bc08e8d5c..a36c6bdea18 100644 --- a/packages/modules/packages/witness/packages/abstract/src/AbstractWitness.ts +++ b/packages/modules/packages/witness/packages/abstract/src/AbstractWitness.ts @@ -1,6 +1,7 @@ import { assertEx } from '@xylabs/assert' import { ArchivistInstance } from '@xyo-network/archivist-model' -import { QueryBoundWitness, QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitness } from '@xyo-network/boundwitness-model' import { PayloadHasher } from '@xyo-network/core' import { AbstractModuleInstance } from '@xyo-network/module-abstract' import { creatableModule, ModuleConfig, ModuleQueryHandlerResult } from '@xyo-network/module-model' diff --git a/packages/node/packages/express/packages/routes/src/routes/address/post/getQueryConfig.ts b/packages/node/packages/express/packages/routes/src/routes/address/post/getQueryConfig.ts index 21f9dade08b..e28bd975b88 100644 --- a/packages/node/packages/express/packages/routes/src/routes/address/post/getQueryConfig.ts +++ b/packages/node/packages/express/packages/routes/src/routes/address/post/getQueryConfig.ts @@ -1,5 +1,4 @@ -import { QueryBoundWitness } from '@xyo-network/boundwitness-builder' -import { BoundWitness, BoundWitnessSchema } from '@xyo-network/boundwitness-model' +import { BoundWitness, BoundWitnessSchema, QueryBoundWitness } from '@xyo-network/boundwitness-model' import { AbstractModule } from '@xyo-network/module-abstract' import { Module, ModuleConfig, ModuleConfigSchema } from '@xyo-network/module-model' import { ArchiveModuleConfig } from '@xyo-network/node-core-model' diff --git a/packages/node/packages/express/packages/routes/src/routes/address/post/post.ts b/packages/node/packages/express/packages/routes/src/routes/address/post/post.ts index b26f02601ed..fc586942f9a 100644 --- a/packages/node/packages/express/packages/routes/src/routes/address/post/post.ts +++ b/packages/node/packages/express/packages/routes/src/routes/address/post/post.ts @@ -1,6 +1,6 @@ import { assertEx } from '@xylabs/assert' import { asyncHandler } from '@xylabs/sdk-api-express-ecs' -import { QueryBoundWitness } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitness } from '@xyo-network/boundwitness-model' import { Module, ModuleQueryResult } from '@xyo-network/module-model' import { trimAddressPrefix } from '@xyo-network/node-core-lib' import { Payload } from '@xyo-network/payload-model' diff --git a/packages/node/packages/express/packages/test/src/routes/node/node.spec.ts b/packages/node/packages/express/packages/test/src/routes/node/node.spec.ts index cc5f4324a07..05cbfc7d1c0 100644 --- a/packages/node/packages/express/packages/test/src/routes/node/node.spec.ts +++ b/packages/node/packages/express/packages/test/src/routes/node/node.spec.ts @@ -1,7 +1,7 @@ import { Account } from '@xyo-network/account' import { AddressPayload, AddressSchema } from '@xyo-network/address-payload-plugin' -import { QueryBoundWitness, QueryBoundWitnessBuilder } from '@xyo-network/boundwitness-builder' -import { BoundWitness, BoundWitnessSchema } from '@xyo-network/boundwitness-model' +import { QueryBoundWitnessBuilder } from '@xyo-network/boundwitness-builder' +import { BoundWitness, BoundWitnessSchema, QueryBoundWitness } from '@xyo-network/boundwitness-model' import { ModuleDiscoverQuerySchema } from '@xyo-network/module-model' import { PayloadBuilder } from '@xyo-network/payload-builder' import { Payload } from '@xyo-network/payload-model' diff --git a/packages/plugins/packages/payloadset/packages/blockchain/packages/ethereum/packages/gas/packages/ethers/src/spec/Witness.spec.ts b/packages/plugins/packages/payloadset/packages/blockchain/packages/ethereum/packages/gas/packages/ethers/src/spec/Witness.spec.ts index b7d5c485ad0..7a12cc21f7c 100644 --- a/packages/plugins/packages/payloadset/packages/blockchain/packages/ethereum/packages/gas/packages/ethers/src/spec/Witness.spec.ts +++ b/packages/plugins/packages/payloadset/packages/blockchain/packages/ethereum/packages/gas/packages/ethers/src/spec/Witness.spec.ts @@ -13,6 +13,7 @@ import { testIf } from '@xylabs/jest-helpers' /** * @group crypto + * @group slow */ describe('EthereumGasEthersWitness', () => { diff --git a/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.data.spec.ts b/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.data.spec.ts index ba0ecd2a3a3..c86befaa256 100644 --- a/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.data.spec.ts +++ b/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.data.spec.ts @@ -8,6 +8,10 @@ import { ImageThumbnailWitness } from '../Witness' // eslint-disable-next-line import/no-named-as-default-member const testIfHasBin = (bin: string) => (hasbin.sync(bin) ? it : it.skip) +/** + * @group thumbnail + */ + describe('ImageThumbnailWitness', () => { testIfHasBin('magick')('DATA [medium/png]', async () => { const witness = await ImageThumbnailWitness.create({ account: await HDWallet.random() }) diff --git a/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.https.spec.ts b/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.https.spec.ts index c83ac3ccced..3d8e14ee0be 100644 --- a/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.https.spec.ts +++ b/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.https.spec.ts @@ -8,6 +8,10 @@ import { ImageThumbnailWitness } from '../Witness' // eslint-disable-next-line import/no-named-as-default-member const describeIfHasBin = (bin: string) => (hasbin.sync(bin) ? describe : describe.skip) +/** + * @group thumbnail + */ + describeIfHasBin('magick')('ImageThumbnailWitness', () => { let witness: ImageThumbnailWitness beforeAll(async () => { diff --git a/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.ipfs.spec.ts b/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.ipfs.spec.ts index f3134e08ea9..8435a17699f 100644 --- a/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.ipfs.spec.ts +++ b/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.ipfs.spec.ts @@ -9,6 +9,10 @@ import { ImageThumbnailWitness } from '../Witness' // eslint-disable-next-line import/no-named-as-default-member const testIfHasBin = (bin: string) => (hasbin.sync(bin) ? it : it.skip) +/** + * @group thumbnail + */ + describe('ImageThumbnailWitness', () => { let witness: ImageThumbnailWitness beforeAll(async () => { diff --git a/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.sentinel.spec.ts b/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.sentinel.spec.ts index 995dbc1a4a3..f5a7daf0762 100644 --- a/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.sentinel.spec.ts +++ b/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.sentinel.spec.ts @@ -10,6 +10,10 @@ import { mock } from 'jest-mock-extended' import { ImageThumbnailWitness } from '../Witness' +/** + * @group thumbnail + */ + describe('Witness', () => { describe('when behind sentinel', () => { const archivistName = 'archivist' diff --git a/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.spec.ts b/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.spec.ts index dfce5f058cd..6f8421fffa4 100644 --- a/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.spec.ts +++ b/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.spec.ts @@ -3,6 +3,10 @@ import { mock } from 'jest-mock-extended' import { ImageThumbnailWitness } from '../Witness' +/** + * @group thumbnail + */ + describe('Witness', () => { describe('checkIpfsUrl', () => { const logger = mock() diff --git a/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.video.spec.ts b/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.video.spec.ts index 4c880f1eb09..9d0b31c54ba 100644 --- a/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.video.spec.ts +++ b/packages/plugins/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.video.spec.ts @@ -23,6 +23,10 @@ const testVideoFormat = async (witness: ImageThumbnailWitness, url: string) => { expect(fileType?.mime).toBe('image/png') } +/** + * @group thumbnail + */ + describeIfHasBin('magick')('ImageThumbnailWitness', () => { describe('with video type', () => { let witness: ImageThumbnailWitness diff --git a/packages/protocol/packages/boundwitness/packages/builder/src/Builder.ts b/packages/protocol/packages/boundwitness/packages/builder/src/Builder.ts index e5e95d02c1e..2748a384704 100644 --- a/packages/protocol/packages/boundwitness/packages/builder/src/Builder.ts +++ b/packages/protocol/packages/boundwitness/packages/builder/src/Builder.ts @@ -24,6 +24,7 @@ export class BoundWitnessBuilder extends BoundWitnessBuilder { private _query: PayloadWrapper | undefined - private _resultSet: PayloadWrapper | undefined override async hashableFields(): Promise { return { @@ -25,10 +24,4 @@ export class QueryBoundWitnessBuilder< this.payload(this._query.payload()) return this } - - resultSet(payloadSet: T) { - this._resultSet = PayloadWrapper.wrap(payloadSet) - this.payload(this._resultSet.payload()) - return this - } } diff --git a/packages/protocol/packages/boundwitness/packages/builder/src/Query/QueryBoundWitnessValidator.ts b/packages/protocol/packages/boundwitness/packages/builder/src/Query/QueryBoundWitnessValidator.ts index 73783d8113f..593a8517826 100644 --- a/packages/protocol/packages/boundwitness/packages/builder/src/Query/QueryBoundWitnessValidator.ts +++ b/packages/protocol/packages/boundwitness/packages/builder/src/Query/QueryBoundWitnessValidator.ts @@ -1,11 +1,11 @@ import { assertEx } from '@xylabs/assert' +import { QueryBoundWitness, QueryBoundWitnessSchema } from '@xyo-network/boundwitness-model' import { BoundWitnessValidator } from '@xyo-network/boundwitness-validator' import { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper' import { handleError } from '@xyo-network/error' import { PayloadSetPayload, Query } from '@xyo-network/payload-model' import { PayloadWrapper } from '@xyo-network/payload-wrapper' -import { QueryBoundWitness, QueryBoundWitnessSchema } from './QueryBoundWitness' export class QueryBoundWitnessValidator extends BoundWitnessValidator { private _query: PayloadWrapper | undefined diff --git a/packages/protocol/packages/boundwitness/packages/builder/src/Query/QueryBoundWitnessWrapper.ts b/packages/protocol/packages/boundwitness/packages/builder/src/Query/QueryBoundWitnessWrapper.ts index 068bafb0cce..2daa53814a8 100644 --- a/packages/protocol/packages/boundwitness/packages/builder/src/Query/QueryBoundWitnessWrapper.ts +++ b/packages/protocol/packages/boundwitness/packages/builder/src/Query/QueryBoundWitnessWrapper.ts @@ -1,13 +1,11 @@ import { assertEx } from '@xylabs/assert' import { compact } from '@xylabs/lodash' +import { QueryBoundWitness } from '@xyo-network/boundwitness-model' import { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper' import { PayloadHasher } from '@xyo-network/core' import { Payload, PayloadSetPayload, Query } from '@xyo-network/payload-model' import { PayloadWrapper } from '@xyo-network/payload-wrapper' -import { QueryBoundWitness } from './QueryBoundWitness' -import { QueryBoundWitnessValidator } from './QueryBoundWitnessValidator' - export class QueryBoundWitnessWrapper extends BoundWitnessWrapper { private _payloadsWithoutQuery: PayloadWrapper[] | undefined private _query: T | undefined @@ -30,25 +28,12 @@ export class QueryBoundWitnessWrapper extends BoundWitn throw Error(`Unable to parse [${typeof obj}]`) } - override getErrors() { - return new QueryBoundWitnessValidator(this.boundwitness).validate() - } - async getQuery(): Promise { const payloadMap = await this.allPayloadMap() this._query = this._query ?? (payloadMap[this.boundwitness.query] as T | undefined) return assertEx(this._query, `Missing Query [${this.boundwitness}]`) } - async getResultSet() { - const resultSetHash = this.boundwitness.resultSet - const payloadMap = await this.payloadMap() - return assertEx( - (this._resultSet = this._resultSet ?? (resultSetHash ? (payloadMap[resultSetHash] as PayloadSetPayload | undefined) : undefined)), - `Missing resultSet [${resultSetHash}]`, - ) - } - override async getWrappedPayloads(): Promise[]> { this._payloadsWithoutQuery = this._payloadsWithoutQuery ?? diff --git a/packages/protocol/packages/boundwitness/packages/builder/src/Query/index.ts b/packages/protocol/packages/boundwitness/packages/builder/src/Query/index.ts index aa341b770ae..291d964f089 100644 --- a/packages/protocol/packages/boundwitness/packages/builder/src/Query/index.ts +++ b/packages/protocol/packages/boundwitness/packages/builder/src/Query/index.ts @@ -1,4 +1,2 @@ -export * from './QueryBoundWitness' export * from './QueryBoundWitnessBuilder' -export * from './QueryBoundWitnessValidator' export * from './QueryBoundWitnessWrapper' diff --git a/packages/protocol/packages/boundwitness/packages/model/src/models/BoundWitness.ts b/packages/protocol/packages/boundwitness/packages/model/src/BoundWitness/BoundWitness.ts similarity index 66% rename from packages/protocol/packages/boundwitness/packages/model/src/models/BoundWitness.ts rename to packages/protocol/packages/boundwitness/packages/model/src/BoundWitness/BoundWitness.ts index da8c18832c9..028943a2357 100644 --- a/packages/protocol/packages/boundwitness/packages/model/src/models/BoundWitness.ts +++ b/packages/protocol/packages/boundwitness/packages/model/src/BoundWitness/BoundWitness.ts @@ -3,13 +3,17 @@ import { Payload } from '@xyo-network/payload-model' import { BoundWitnessSchema } from './BoundWitnessSchema' export type BoundWitnessFields = { + /** @field Array of signatures by the accounts that are listed in addresses */ _signatures: string[] + /** @field Array of signatures by the accounts that are listed in addresses */ addresses: string[] blockNumber?: number error_hashes?: string[] payload_hashes: string[] payload_schemas: string[] previous_hashes: (string | null)[] + /** @field Hash of the QueryBoundWitness that caused this BoundWitness to be created */ + sourceQuery?: string timestamp?: number } @@ -17,6 +21,3 @@ export type BoundWitness = Payload< T extends Payload ? BoundWitnessFields & T : BoundWitnessFields, T extends Payload ? T['schema'] : BoundWitnessSchema > - -export const isBoundWitness = (x?: Payload | null): x is BoundWitness => x?.schema === BoundWitnessSchema -export const notBoundWitness = (x?: Payload | null): x is Payload => x?.schema !== BoundWitnessSchema diff --git a/packages/protocol/packages/boundwitness/packages/model/src/models/BoundWitnessJsonSchema.ts b/packages/protocol/packages/boundwitness/packages/model/src/BoundWitness/BoundWitnessJsonSchema.ts similarity index 100% rename from packages/protocol/packages/boundwitness/packages/model/src/models/BoundWitnessJsonSchema.ts rename to packages/protocol/packages/boundwitness/packages/model/src/BoundWitness/BoundWitnessJsonSchema.ts diff --git a/packages/protocol/packages/boundwitness/packages/model/src/models/BoundWitnessSchema.ts b/packages/protocol/packages/boundwitness/packages/model/src/BoundWitness/BoundWitnessSchema.ts similarity index 100% rename from packages/protocol/packages/boundwitness/packages/model/src/models/BoundWitnessSchema.ts rename to packages/protocol/packages/boundwitness/packages/model/src/BoundWitness/BoundWitnessSchema.ts diff --git a/packages/protocol/packages/boundwitness/packages/model/src/models/index.ts b/packages/protocol/packages/boundwitness/packages/model/src/BoundWitness/index.ts similarity index 100% rename from packages/protocol/packages/boundwitness/packages/model/src/models/index.ts rename to packages/protocol/packages/boundwitness/packages/model/src/BoundWitness/index.ts diff --git a/packages/protocol/packages/boundwitness/packages/builder/src/Query/QueryBoundWitness.ts b/packages/protocol/packages/boundwitness/packages/model/src/QueryBoundWitness.ts similarity index 74% rename from packages/protocol/packages/boundwitness/packages/builder/src/Query/QueryBoundWitness.ts rename to packages/protocol/packages/boundwitness/packages/model/src/QueryBoundWitness.ts index e28a37de0fc..4181cb037a8 100644 --- a/packages/protocol/packages/boundwitness/packages/builder/src/Query/QueryBoundWitness.ts +++ b/packages/protocol/packages/boundwitness/packages/model/src/QueryBoundWitness.ts @@ -1,13 +1,15 @@ -import { BoundWitness, BoundWitnessSchema, isBoundWitness } from '@xyo-network/boundwitness-model' import { Payload } from '@xyo-network/payload-model' +import { BoundWitness, BoundWitnessSchema } from './BoundWitness' +import { isBoundWitness } from './isBoundWitness' + export type QueryBoundWitnessSchema = BoundWitnessSchema export const QueryBoundWitnessSchema: QueryBoundWitnessSchema = BoundWitnessSchema export type QueryBoundWitness = BoundWitness<{ query: string resultSet?: string - schema: BoundWitnessSchema + schema: QueryBoundWitnessSchema }> export const isQueryBoundWitness = (x?: Payload | null): x is QueryBoundWitness => isBoundWitness(x) && (x as QueryBoundWitness)?.query !== undefined diff --git a/packages/protocol/packages/boundwitness/packages/model/src/index.ts b/packages/protocol/packages/boundwitness/packages/model/src/index.ts index 327a7ef9def..efac3aec6a2 100644 --- a/packages/protocol/packages/boundwitness/packages/model/src/index.ts +++ b/packages/protocol/packages/boundwitness/packages/model/src/index.ts @@ -1,2 +1,3 @@ -export * from './isBoundWitnessPayload' -export * from './models' +export * from './BoundWitness' +export * from './isBoundWitness' +export * from './QueryBoundWitness' diff --git a/packages/protocol/packages/boundwitness/packages/model/src/isBoundWitness.ts b/packages/protocol/packages/boundwitness/packages/model/src/isBoundWitness.ts new file mode 100644 index 00000000000..407f0a70d68 --- /dev/null +++ b/packages/protocol/packages/boundwitness/packages/model/src/isBoundWitness.ts @@ -0,0 +1,9 @@ +import { isPayloadOfSchemaType, notPayloadOfSchemaType } from '@xyo-network/payload-model' + +import { BoundWitness, BoundWitnessSchema } from './BoundWitness' + +export const isBoundWitness = isPayloadOfSchemaType(BoundWitnessSchema) +export const notBoundWitness = notPayloadOfSchemaType(BoundWitnessSchema) + +/** @deprecated use isBoundWitness instead*/ +export const isBoundWitnessPayload = isBoundWitness diff --git a/packages/protocol/packages/boundwitness/packages/model/src/isBoundWitnessPayload.ts b/packages/protocol/packages/boundwitness/packages/model/src/isBoundWitnessPayload.ts deleted file mode 100644 index 93ef6fff32d..00000000000 --- a/packages/protocol/packages/boundwitness/packages/model/src/isBoundWitnessPayload.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { isPayloadOfSchemaType } from '@xyo-network/payload-model' - -import { BoundWitness, BoundWitnessSchema } from './models' - -export const isBoundWitnessPayload = isPayloadOfSchemaType(BoundWitnessSchema) diff --git a/packages/protocol/packages/boundwitness/packages/model/tsconfig.json b/packages/protocol/packages/boundwitness/packages/model/tsconfig.json index 98bc97f8fe0..e7b48190167 100644 --- a/packages/protocol/packages/boundwitness/packages/model/tsconfig.json +++ b/packages/protocol/packages/boundwitness/packages/model/tsconfig.json @@ -1,6 +1,5 @@ { "compilerOptions": { - "incremental": false, "typeRoots": [] }, "exclude": ["dist", "docs", "packages", "node_modules"], diff --git a/packages/protocol/packages/payload/packages/model/src/isPayloadOfSchemaType.ts b/packages/protocol/packages/payload/packages/model/src/isPayloadOfSchemaType.ts index 2cb60b5ecea..72128faff01 100644 --- a/packages/protocol/packages/payload/packages/model/src/isPayloadOfSchemaType.ts +++ b/packages/protocol/packages/payload/packages/model/src/isPayloadOfSchemaType.ts @@ -3,3 +3,7 @@ import { Payload } from './Payload' export const isPayloadOfSchemaType = (schema: string) => { return (x?: Payload | null): x is T => x?.schema === schema } + +export const notPayloadOfSchemaType = (schema: string) => { + return (x?: Payload | null): x is T => x?.schema !== schema +} diff --git a/packages/sdk/packages/payloadset-plugin/src/Plugin.ts b/packages/sdk/packages/payloadset-plugin/src/Plugin.ts index b8c6ceb2f96..6f99c9a82ee 100644 --- a/packages/sdk/packages/payloadset-plugin/src/Plugin.ts +++ b/packages/sdk/packages/payloadset-plugin/src/Plugin.ts @@ -1,4 +1,5 @@ -import { QueryBoundWitness, QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitness } from '@xyo-network/boundwitness-model' import { Validator } from '@xyo-network/core' import { DivinerModule } from '@xyo-network/diviner' import { PayloadSetPayload } from '@xyo-network/payload-model' diff --git a/packages/sdk/packages/payloadset-plugin/src/Resolver.ts b/packages/sdk/packages/payloadset-plugin/src/Resolver.ts index c281213f63b..3c835505a88 100644 --- a/packages/sdk/packages/payloadset-plugin/src/Resolver.ts +++ b/packages/sdk/packages/payloadset-plugin/src/Resolver.ts @@ -1,4 +1,5 @@ -import { QueryBoundWitness, QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder' +import { QueryBoundWitness } from '@xyo-network/boundwitness-model' import { PayloadHasher, Validator } from '@xyo-network/core' import { DivinerModule, DivinerParams } from '@xyo-network/diviner-model' import { PayloadSetPayload } from '@xyo-network/payload-model'