|
1 | 1 | import { AbstractIdentifierProvider } from '@veramo/did-manager'; |
2 | 2 | import { DIDDocument, IAgentContext, IIdentifier, IKey, IKeyManager, IService } from '@veramo/core'; |
3 | | -import LTO, { Binary, Account, IdentityBuilder, Transaction } from '@ltonetwork/lto'; |
| 3 | +import LTO, { Binary, Account, IdentityBuilder, Transaction, PublicNode } from '@ltonetwork/lto'; |
4 | 4 | import { IAccountIn, ISigner, TDIDRelationship } from '@ltonetwork/lto/interfaces'; |
5 | 5 | import { accountAsKey, ofIdentifier, ofKey } from './convert'; |
6 | 6 |
|
7 | | -interface LtoOptions { |
| 7 | +interface LtoOptionsWithLTO { |
| 8 | + defaultKms: string; |
| 9 | + sponsor?: ISigner | IAccountIn; |
| 10 | + lto: LTO; |
| 11 | +} |
| 12 | +interface LtoOptionsWithSettings { |
8 | 13 | defaultKms: string; |
9 | 14 | sponsor?: ISigner | IAccountIn; |
10 | | - lto?: LTO; |
11 | 15 | networkId?: string; |
12 | 16 | nodeAddress?: string; |
13 | 17 | nodeApiKey?: string; |
14 | 18 | } |
| 19 | +type LtoOptions = LtoOptionsWithLTO | LtoOptionsWithSettings; |
15 | 20 |
|
16 | 21 | interface AccountOptions extends IAccountIn { |
17 | 22 | publicKeyHex?: string; |
@@ -52,9 +57,13 @@ export class LtoDIDProvider extends AbstractIdentifierProvider { |
52 | 57 |
|
53 | 58 | this.defaultKms = options.defaultKms; |
54 | 59 |
|
55 | | - this.lto = options.lto ?? new LTO(options.networkId ?? 'T'); |
56 | | - if (options.lto && options.networkId && options.lto.networkId !== options.networkId) { |
57 | | - throw new Error(`Network id mismatch: expected '${options.networkId}', got '${options.lto.networkId}'`); |
| 60 | + if ('lto' in options) { |
| 61 | + this.lto = options.lto; |
| 62 | + } else { |
| 63 | + this.lto = new LTO(options.networkId); |
| 64 | + if (options.nodeAddress || options.nodeApiKey) { |
| 65 | + this.lto.node = new PublicNode(options.nodeAddress, options.nodeApiKey); |
| 66 | + } |
58 | 67 | } |
59 | 68 |
|
60 | 69 | if (options.sponsor) { |
|
0 commit comments