@xyo-network/os-runtime 3.0.14 → 3.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/os-runtime",
3
- "version": "3.0.14",
3
+ "version": "3.0.16",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -39,8 +39,8 @@
39
39
  "@xyo-network/archivist": "^3.0.7",
40
40
  "@xyo-network/archivist-indexeddb": "^3.0.7",
41
41
  "@xyo-network/archivist-model": "^3.0.7",
42
- "@xyo-network/bios": "^3.0.14",
43
- "@xyo-network/bios-model": "^3.0.14",
42
+ "@xyo-network/bios": "^3.0.16",
43
+ "@xyo-network/bios-model": "^3.0.16",
44
44
  "@xyo-network/bridge-model": "^3.0.7",
45
45
  "@xyo-network/diviner-abstract": "^3.0.7",
46
46
  "@xyo-network/diviner-model": "^3.0.7",
@@ -48,8 +48,8 @@
48
48
  "@xyo-network/diviner-payload-indexeddb": "^3.0.7",
49
49
  "@xyo-network/diviner-payload-model": "^3.0.7",
50
50
  "@xyo-network/diviner-temporal-indexing-model": "^3.0.7",
51
- "@xyo-network/kernel": "^3.0.14",
52
- "@xyo-network/kernel-model": "^3.0.14",
51
+ "@xyo-network/kernel": "^3.0.16",
52
+ "@xyo-network/kernel-model": "^3.0.16",
53
53
  "@xyo-network/manifest": "^3.0.7",
54
54
  "@xyo-network/manifest-wrapper": "^3.0.7",
55
55
  "@xyo-network/module-abstract": "^3.0.7",
@@ -58,7 +58,7 @@
58
58
  "@xyo-network/module-model": "^3.0.7",
59
59
  "@xyo-network/module-resolver": "^3.0.7",
60
60
  "@xyo-network/node-model": "^3.0.7",
61
- "@xyo-network/os-model": "^3.0.14",
61
+ "@xyo-network/os-model": "^3.0.16",
62
62
  "@xyo-network/payload-builder": "^3.0.7",
63
63
  "@xyo-network/payload-model": "^3.0.7",
64
64
  "@xyo-network/wallet-model": "^3.0.7",
@@ -72,7 +72,7 @@
72
72
  "@types/uuid": "^10.0.0",
73
73
  "@xylabs/ts-scripts-yarn3": "^4.0.1",
74
74
  "@xylabs/tsconfig": "^4.0.1",
75
- "@xyo-network/bios-nodejs": "^3.0.14",
75
+ "@xyo-network/bios-nodejs": "^3.0.16",
76
76
  "typescript": "^5.5.4",
77
77
  "vitest": "^2.0.5"
78
78
  },
package/src/Caller.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
2
  import type { Hash } from '@xylabs/hex'
3
+ import type { Promisable } from '@xylabs/promise'
3
4
  import type { AccountInstance } from '@xyo-network/account'
4
- import { Account } from '@xyo-network/account'
5
5
  import type { PayloadDivinerQueryPayload } from '@xyo-network/diviner-payload-model'
6
6
  import { PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model'
7
7
  import type {
@@ -10,8 +10,6 @@ import type {
10
10
  DappInjectableParams,
11
11
  DappIntent,
12
12
  RegisteredDappAccess,
13
- SigningKey,
14
- SigningKeyFields,
15
13
  XyOsContext,
16
14
  } from '@xyo-network/os-model'
17
15
  import {
@@ -20,7 +18,6 @@ import {
20
18
  DappIntentTypes,
21
19
  DappMode,
22
20
  RegisteredDappAccessSchema,
23
- SigningKeySchema,
24
21
  } from '@xyo-network/os-model'
25
22
  import { PayloadBuilder } from '@xyo-network/payload-builder'
26
23
  import type { Payload, WithMeta } from '@xyo-network/payload-model'
@@ -116,29 +113,11 @@ export class DappCaller extends DappCallerBase {
116
113
  /**
117
114
  * Get the user wallet
118
115
  */
119
- async getUserAccount(dappName: string, useSigners?: boolean): Promise<AccountInstance> {
120
- // old implementation
121
- const diviner = await this.getDappArchivistPayloadDiviner()
122
- const query: PayloadDivinerQueryPayload<SigningKeyFields> = {
123
- dappName,
124
- limit: 1,
125
- order: 'desc',
126
- schema: PayloadDivinerQuerySchema,
127
- schemas: [SigningKeySchema],
128
- }
129
- const [payload] = assertEx(await diviner.divine([query]), () => 'Unable to find user wallet') as WithMeta<SigningKey>[]
130
- if (payload) {
131
- console.log('*** old implementation address', await Account.fromPrivateKey(payload.privateKey))
132
- if (!useSigners) return await Account.fromPrivateKey(payload.privateKey)
133
- } else {
134
- throw new Error('Unable to find user wallet')
135
- }
136
-
116
+ getUserAccount(dappName: string): Promisable<AccountInstance> {
137
117
  // new implementation
138
- const account = this.context.user.signers?.get('Name Service')
118
+ const account = this.context.user.signers?.get(dappName)
139
119
 
140
120
  if (account) {
141
- console.log('*** new implementation address', account)
142
121
  return account
143
122
  } else {
144
123
  throw new Error('Unable to find user wallet')
@@ -148,19 +127,8 @@ export class DappCaller extends DappCallerBase {
148
127
  /**
149
128
  * Get all wallets for the user
150
129
  */
151
- async getUserAccountsAll(): Promise<SigningKey[]> {
152
- const diviner = await this.getDappArchivistPayloadDiviner()
153
- const query: PayloadDivinerQueryPayload<SigningKeyFields> = {
154
- order: 'desc',
155
- schema: PayloadDivinerQuerySchema,
156
- schemas: [SigningKeySchema],
157
- }
158
- const payloads = assertEx(await diviner.divine([query]), () => 'Unable to find user wallet') as WithMeta<SigningKey>[]
159
- if (payloads?.length) {
160
- return payloads
161
- } else {
162
- throw new Error('Unable to find user wallet')
163
- }
130
+ getUserAccountsAll(): Promisable<AccountInstance[]> {
131
+ return [...this.context.user.signers?.values() ?? []]
164
132
  }
165
133
 
166
134
  /**
@@ -7,7 +7,6 @@ import type { InsertableConstructor } from '../../lib/index.ts'
7
7
  import { createInsertable } from '../../lib/index.ts'
8
8
  import { DappAccessPayloads } from './DappAccessPayloads.ts'
9
9
  import { NodeInfoPayload } from './NodeInfoPayload.ts'
10
- import { SigningKeyPayloads } from './SigningKeyPayloads.ts'
11
10
 
12
11
  export class DefaultPayloads {
13
12
  constructor(
@@ -17,7 +16,7 @@ export class DefaultPayloads {
17
16
  ) {}
18
17
 
19
18
  async insert() {
20
- const insertables: InsertableConstructor[] = [NodeInfoPayload, SigningKeyPayloads, DappAccessPayloads]
19
+ const insertables: InsertableConstructor[] = [NodeInfoPayload, DappAccessPayloads]
21
20
  const insertPayloads: Payload[] = []
22
21
  for (const insertable of insertables) {
23
22
  const classInstance = createInsertable(insertable, this.xyOs, this.dappName)
@@ -1,13 +0,0 @@
1
- import type { DappName, XyOsContext } from '@xyo-network/os-model';
2
- import type { DefaultPayloadsInsertable } from '../../lib/index.ts';
3
- export declare class SigningKeyPayloads implements DefaultPayloadsInsertable {
4
- private context;
5
- private dappName;
6
- constructor(context: XyOsContext, dappName: DappName);
7
- payloads(): Promise<({
8
- schema: string;
9
- } & import("@xyo-network/payload-model").PayloadFields)[]>;
10
- private resolveUserWallet;
11
- private signingKeyPayload;
12
- }
13
- //# sourceMappingURL=SigningKeyPayloads.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SigningKeyPayloads.d.ts","sourceRoot":"","sources":["../../../../../src/classes/node/DefaultPayloads/SigningKeyPayloads.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAMlE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAA;AAenE,qBAAa,kBAAmB,YAAW,yBAAyB;IAEhE,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,QAAQ;gBADR,OAAO,EAAE,WAAW,EACpB,QAAQ,EAAE,QAAQ;IAGtB,QAAQ;;;YAqBA,iBAAiB;YAajB,iBAAiB;CAgBhC"}
@@ -1,81 +0,0 @@
1
- import { assertEx } from '@xylabs/assert'
2
- import { hexFrom } from '@xylabs/hex'
3
- import { HDWallet } from '@xyo-network/account'
4
- import type { DappName, XyOsContext } from '@xyo-network/os-model'
5
- import { mnemonicArrayToString, SigningKeySchema } from '@xyo-network/os-model'
6
- import type { Payload } from '@xyo-network/payload-model'
7
- import { isAnyPayload } from '@xyo-network/payload-model'
8
- import type { WalletInstance } from '@xyo-network/wallet-model'
9
-
10
- import type { DefaultPayloadsInsertable } from '../../lib/index.ts'
11
- import { OsSettingsCaller } from '../../settings/index.ts'
12
-
13
- const DappsWithAdditionalPayloads = new Set(['Profile'])
14
-
15
- const DefaultName: DappName = 'Name Service' as const
16
-
17
- const DEFAULT_DAPP_ACCOUNT_PATHS: Record<string, string> = { [DefaultName]: "1'/1" } as const
18
-
19
- // WIP - for now, dApps listed here can gain access to the signing key for other dapps
20
- // In the future, this will be controlled by the user
21
- const ADDITIONAL_DAPP_ACCOUNT_PATHS: Record<string, Record<string, string>>
22
- = { ['Profile']: { [DefaultName]: DEFAULT_DAPP_ACCOUNT_PATHS[DefaultName] } } as const
23
-
24
- /** @deprecated - use user signers from os context */
25
- export class SigningKeyPayloads implements DefaultPayloadsInsertable {
26
- constructor(
27
- private context: XyOsContext,
28
- private dappName: DappName,
29
- ) {}
30
-
31
- async payloads() {
32
- const wallet = await this.resolveUserWallet()
33
-
34
- // get the signing key payloads for the default dapp account
35
- const defaultDappAccountSigningKeyPayloads = await this.signingKeyPayload(wallet, this.dappName, DEFAULT_DAPP_ACCOUNT_PATHS[this.dappName])
36
-
37
- // and any additional dapp accounts
38
- const additionalDappAccountSigningKeyPayloads: (Payload | undefined)[] = []
39
- for (const [dappName, accountPaths] of Object.entries(ADDITIONAL_DAPP_ACCOUNT_PATHS)) {
40
- if (dappName !== this.dappName || !DappsWithAdditionalPayloads.has(dappName)) continue
41
-
42
- for (const additionalDappAccountName of Object.keys(accountPaths)) {
43
- const signingKeyPayload = await this.signingKeyPayload(wallet, additionalDappAccountName, accountPaths[additionalDappAccountName])
44
- additionalDappAccountSigningKeyPayloads.push(signingKeyPayload)
45
- }
46
- }
47
-
48
- // filter so we only return valid payloads
49
- return [...additionalDappAccountSigningKeyPayloads, defaultDappAccountSigningKeyPayloads].filter(isAnyPayload) as Payload[]
50
- }
51
-
52
- private async resolveUserWallet() {
53
- // get the user's wallet
54
- const settingsCaller = new OsSettingsCaller(this.context)
55
- const latestWallet = await settingsCaller.getLatestUserWallet()
56
-
57
- // find the phrase
58
- const phrase = mnemonicArrayToString(latestWallet.mnemonic.mnemonic)
59
- const assertedPhrase = assertEx(phrase, () => 'No phrase found in latest wallet')
60
-
61
- // create a wallet instance
62
- return await HDWallet.fromPhrase(assertedPhrase)
63
- }
64
-
65
- private async signingKeyPayload(wallet: WalletInstance, name: string, path?: string) {
66
- if (path) {
67
- // derive the sub account
68
- const subAccount = await wallet.derivePath(path)
69
-
70
- // get the private key
71
- const privateKey = hexFrom(subAccount.privateKey, { prefix: false })
72
-
73
- // return the payload
74
- return {
75
- dappName: name,
76
- privateKey,
77
- schema: SigningKeySchema,
78
- }
79
- }
80
- }
81
- }