Skip to content

Commit f6f8c4b

Browse files
committed
LTO DID Provider constructor takes either an LTO object or network id and node address, but not both.
1 parent 3165347 commit f6f8c4b

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/lto-did-provider.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
import { AbstractIdentifierProvider } from '@veramo/did-manager';
22
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';
44
import { IAccountIn, ISigner, TDIDRelationship } from '@ltonetwork/lto/interfaces';
55
import { accountAsKey, ofIdentifier, ofKey } from './convert';
66

7-
interface LtoOptions {
7+
interface LtoOptionsWithLTO {
8+
defaultKms: string;
9+
sponsor?: ISigner | IAccountIn;
10+
lto: LTO;
11+
}
12+
interface LtoOptionsWithSettings {
813
defaultKms: string;
914
sponsor?: ISigner | IAccountIn;
10-
lto?: LTO;
1115
networkId?: string;
1216
nodeAddress?: string;
1317
nodeApiKey?: string;
1418
}
19+
type LtoOptions = LtoOptionsWithLTO | LtoOptionsWithSettings;
1520

1621
interface AccountOptions extends IAccountIn {
1722
publicKeyHex?: string;
@@ -52,9 +57,13 @@ export class LtoDIDProvider extends AbstractIdentifierProvider {
5257

5358
this.defaultKms = options.defaultKms;
5459

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+
}
5867
}
5968

6069
if (options.sponsor) {

test/lto-did-provider.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import LTO, {
77
Anchor,
88
Association,
99
Binary,
10-
Data, IdentityBuilder,
10+
Data,
11+
IdentityBuilder,
1112
PublicNode,
1213
Register,
1314
RevokeAssociation,

0 commit comments

Comments
 (0)