Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.

Commit 1272ce7

Browse files
committed
Lint fixes for publish
1 parent 333838a commit 1272ce7

File tree

12 files changed

+11128
-7990
lines changed

12 files changed

+11128
-7990
lines changed

package-lock.json

Lines changed: 5367 additions & 2398 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/interfaces/error.interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export enum IErrorInternal {
9999
NoKeypairsProvided = 'No key-pairs provided',
100100
NoPassPhraseProvided = 'No passphrase provided',
101101
NoComputeHostProvided = 'No compute host provided',
102-
UnknownError = 'Unknown Error'
102+
UnknownError = 'Unknown Error',
103103
}
104104

105105
// Custom `Result` wrapper with string error

src/interfaces/general.interfaces.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ export type IClientConfig = {
88
storageHost?: string;
99
intercomHost?: string;
1010
notaryHost?: string;
11-
passphrase: string; /* Required */
11+
passphrase: string /* Required */;
1212
};
1313

1414
// Init
1515
export type INewWalletResponse = {
16-
seedphrase: string,
17-
masterKey: IMasterKeyEncrypted,
18-
}
16+
seedphrase: string;
17+
masterKey: IMasterKeyEncrypted;
18+
};
1919

2020
/* -------------------------------------------------------------------------- */
2121
/* Internal Interfaces */

src/interfaces/network.interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,4 @@ export type IPendingRbTxDetails = {
242242
export type IMakeRbPaymentResponse = {
243243
druid: string;
244244
encryptedTx: ICreateTransactionEncrypted;
245-
};
245+
};

src/mgmt/key.mgmt.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ export function generateSeed(): IResult<string> {
7575
* @param passphrase {string} - Passphrase as a string
7676
*/
7777
export function getPassphraseBuffer(passphrase: string): IResult<Uint8Array> {
78-
if (passphrase == undefined)
79-
return err(IErrorInternal.NoPassPhraseProvided);
78+
if (passphrase == undefined) return err(IErrorInternal.NoPassPhraseProvided);
8079
try {
8180
const hash = sha3_256(passphrase);
8281
const val = truncateByBytesUTF8(hash, 32);
@@ -305,4 +304,4 @@ export function testSeedPhrase(seed: string): boolean {
305304
*/
306305
export function generateSeedPhrase(): string {
307306
return generateSeed().unwrapOr('');
308-
}
307+
}

src/mgmt/tx.mgmt.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,19 @@ export function getInputsForTx(
6262
const enoughRunningTotal = isOfTypeAssetToken
6363
? paymentAsset.Token <= fetchBalanceResponse.total.tokens
6464
: paymentAsset.Receipt.amount <=
65-
fetchBalanceResponse.total.receipts[paymentAsset.Receipt.drs_tx_hash];
65+
fetchBalanceResponse.total.receipts[paymentAsset.Receipt.drs_tx_hash];
6666

6767
if (enoughRunningTotal) {
6868
// Initialize the total amount gathered; apply DRS transaction hash where required
6969
let totalAmountGathered: IAssetToken | IAssetReceipt = isOfTypeAssetToken
7070
? initIAssetToken()
7171
: initIAssetReceipt({
72-
Receipt: {
73-
amount: 0,
74-
drs_tx_hash: paymentAsset.Receipt.drs_tx_hash,
75-
metadata: paymentAsset.Receipt.metadata,
76-
},
77-
});
72+
Receipt: {
73+
amount: 0,
74+
drs_tx_hash: paymentAsset.Receipt.drs_tx_hash,
75+
metadata: paymentAsset.Receipt.metadata,
76+
},
77+
});
7878
// A list of all addresses used to gather inputs
7979
const usedAddresses: string[] = [];
8080
// A list of all addresses which no longer contain usable assets after this transaction is created

src/services/ablock.service.ts

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export class ABlockWallet {
145145
*
146146
* @param {string} seedPhrase - Seed phrase
147147
* @param {IClientConfig} config - Additional configuration parameters
148-
* @param initOffline - Optionally initialize the client without initializing network settings
148+
* @param initOffline - Optionally initialize the client without initializing network settings
149149
* @return {*} {IClientResponse}
150150
* @memberof ABlockWallet
151151
*/
@@ -182,7 +182,7 @@ export class ABlockWallet {
182182
* Common network initialization (retrieval of PoW list for compute and storage)
183183
*
184184
* @param {IClientConfig} config - Configuration parameters
185-
* @return {*} {IClientResponse}
185+
* @return {*} {IClientResponse}
186186
* @memberof ABlockWallet
187187
*/
188188
public async initNetwork(config: IClientConfig): Promise<IClientResponse> {
@@ -194,7 +194,7 @@ export class ABlockWallet {
194194
if (this.mempoolHost == undefined)
195195
return {
196196
status: 'error',
197-
reason: IErrorInternal.NoComputeHostProvided
197+
reason: IErrorInternal.NoComputeHostProvided,
198198
} as IClientResponse;
199199

200200
// Initialize routes proof-of-work for compute host
@@ -205,7 +205,6 @@ export class ABlockWallet {
205205
);
206206
if (initComputeResult.status == 'error') return initComputeResult;
207207

208-
209208
// Optional - Initialize routes proof-of-work for storage host
210209
if (this.storageHost !== undefined) {
211210
this.storageRoutesPoW = new Map();
@@ -356,9 +355,9 @@ export class ABlockWallet {
356355
*/
357356
public async fetchTransactions(transactionHashes: string[]): Promise<IClientResponse> {
358357
try {
359-
if (!this.keyMgmt)
360-
throw new Error(IErrorInternal.ClientNotInitialized);
361-
if (!this.storageHost || !this.storageRoutesPoW) /* Storage is optional on wallet init, but must be initialized here */
358+
if (!this.keyMgmt) throw new Error(IErrorInternal.ClientNotInitialized);
359+
if (!this.storageHost || !this.storageRoutesPoW)
360+
/* Storage is optional on wallet init, but must be initialized here */
362361
throw new Error(IErrorInternal.StorageNotInitialized);
363362
const headers = this.getRequestIdAndNonceHeadersForRoute(
364363
this.mempoolRoutesPoW,
@@ -508,10 +507,8 @@ export class ABlockWallet {
508507
*/
509508
async getNotaryBurnAddress(): Promise<IClientResponse> {
510509
try {
511-
if (!this.keyMgmt)
512-
throw new Error(IErrorInternal.ClientNotInitialized);
513-
if (!this.notaryHost)
514-
throw new Error(IErrorInternal.NotaryNotInitialized);
510+
if (!this.keyMgmt) throw new Error(IErrorInternal.ClientNotInitialized);
511+
if (!this.notaryHost) throw new Error(IErrorInternal.NotaryNotInitialized);
515512
const headers = this.getRequestIdAndNonceHeadersForRoute(
516513
new Map(),
517514
IAPIRoute.GetNotaryBurnAddress,
@@ -555,10 +552,8 @@ export class ABlockWallet {
555552
signatures: IGenericKeyPair<string>,
556553
): Promise<IClientResponse> {
557554
try {
558-
if (!this.keyMgmt)
559-
throw new Error(IErrorInternal.ClientNotInitialized);
560-
if (!this.notaryHost)
561-
throw new Error(IErrorInternal.NotaryNotInitialized);
555+
if (!this.keyMgmt) throw new Error(IErrorInternal.ClientNotInitialized);
556+
if (!this.notaryHost) throw new Error(IErrorInternal.NotaryNotInitialized);
562557
const headers = this.getRequestIdAndNonceHeadersForRoute(
563558
new Map(),
564559
IAPIRoute.GetNotarySignature,
@@ -600,10 +595,7 @@ export class ABlockWallet {
600595
* @return {*} {Promise<IClientResponse>}
601596
* @memberof ABlockWallet
602597
*/
603-
signMessage(
604-
keyPairsToSignWith: IKeypairEncrypted[],
605-
message: string,
606-
): IClientResponse {
598+
signMessage(keyPairsToSignWith: IKeypairEncrypted[], message: string): IClientResponse {
607599
try {
608600
if (this.keyMgmt === undefined) throw new Error(IErrorInternal.ClientNotInitialized);
609601
const keyPairs = throwIfErr(this.keyMgmt.decryptKeypairs(keyPairsToSignWith));
@@ -644,7 +636,6 @@ export class ABlockWallet {
644636
}
645637
}
646638

647-
648639
/**
649640
* Make a payment of a specified token amount to a payment address
650641
*
@@ -711,8 +702,7 @@ export class ABlockWallet {
711702
try {
712703
if (!this.mempoolHost || !this.keyMgmt || !this.mempoolRoutesPoW)
713704
throw new Error(IErrorInternal.ClientNotInitialized);
714-
if (!this.intercomHost)
715-
throw new Error(IErrorInternal.IntercomNotInitialized);
705+
if (!this.intercomHost) throw new Error(IErrorInternal.IntercomNotInitialized);
716706
const senderKeypair = throwIfErr(this.keyMgmt.decryptKeypair(receiveAddress));
717707
const [allAddresses, keyPairMap] = throwIfErr(
718708
this.keyMgmt.getAllAddressesAndKeypairMap(allKeypairs),
@@ -858,8 +848,7 @@ export class ABlockWallet {
858848
try {
859849
if (!this.mempoolHost || !this.keyMgmt || !this.mempoolRoutesPoW)
860850
throw new Error(IErrorInternal.ClientNotInitialized);
861-
if (!this.intercomHost)
862-
throw new Error(IErrorInternal.IntercomNotInitialized);
851+
if (!this.intercomHost) throw new Error(IErrorInternal.IntercomNotInitialized);
863852

864853
// Generate a key-pair map
865854
const [allAddresses, keyPairMap] = throwIfErr(
@@ -1174,23 +1163,21 @@ export class ABlockWallet {
11741163
}
11751164

11761165
/**
1177-
* Get keypairs from localStorage. (Browser)
1178-
* It is recommended to use user defined methods for I/O operations (see https://github.com/ABlockOfficial/A-Block.js#getting-started)
1179-
*
1180-
* @export
1181-
* @param {string} keypairs IKeypairEncrypted[] flattened to a string
1182-
* @return {*} {void}
1183-
*/
1166+
* Get keypairs from localStorage. (Browser)
1167+
* It is recommended to use user defined methods for I/O operations (see https://github.com/ABlockOfficial/A-Block.js#getting-started)
1168+
*
1169+
* @export
1170+
* @param {string} keypairs IKeypairEncrypted[] flattened to a string
1171+
* @return {*} {void}
1172+
*/
11841173
getKeypairs(): IClientResponse {
11851174
try {
11861175
if (!this.keyMgmt) throw new Error(IErrorInternal.ClientNotInitialized);
11871176
return {
11881177
status: 'success',
11891178
reason: ISuccessInternal.KeypairObtained,
11901179
content: {
1191-
getKeypairsResponse: throwIfErr(
1192-
this.keyMgmt.getKeypairs()
1193-
),
1180+
getKeypairsResponse: throwIfErr(this.keyMgmt.getKeypairs()),
11941181
},
11951182
};
11961183
} catch (error) {
@@ -1311,8 +1298,7 @@ export class ABlockWallet {
13111298
try {
13121299
if (!this.mempoolHost || !this.keyMgmt || !this.mempoolRoutesPoW)
13131300
throw new Error(IErrorInternal.ClientNotInitialized);
1314-
if (!this.intercomHost)
1315-
throw new Error(IErrorInternal.IntercomNotInitialized);
1301+
if (!this.intercomHost) throw new Error(IErrorInternal.IntercomNotInitialized);
13161302
const [allAddresses, keyPairMap] = throwIfErr(
13171303
this.keyMgmt.getAllAddressesAndKeypairMap(allKeypairs),
13181304
);

src/services/mgmt.service.ts

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,7 @@ export class mgmtClient {
482482
* @memberof mgmtClient
483483
*/
484484
public signMessage(keypairs: IKeypair[], message: string): IResult<IGenericKeyPair<string>> {
485-
if (keypairs.length < 1)
486-
return err(IErrorInternal.InvalidInputs);
485+
if (keypairs.length < 1) return err(IErrorInternal.InvalidInputs);
487486
const signatures: IGenericKeyPair<string> = {};
488487
for (const keypair of keypairs) {
489488
const signature = nacl.sign.detached(Buffer.from(message), keypair.secretKey);
@@ -493,12 +492,23 @@ export class mgmtClient {
493492
return ok(signatures);
494493
}
495494

496-
public verifyMessage(message: string, signatures: IGenericKeyPair<string>, keypairs: IKeypair[]): IResult<boolean> {
495+
public verifyMessage(
496+
message: string,
497+
signatures: IGenericKeyPair<string>,
498+
keypairs: IKeypair[],
499+
): IResult<boolean> {
497500
if (keypairs.length < 1 || Object.keys(signatures).length != keypairs.length)
498501
return err(IErrorInternal.InvalidInputs);
499502
for (const keypair of keypairs) {
500-
const sig = signatures[getBytesHexString(keypair.publicKey)]
501-
if (!sig || !nacl.sign.detached.verify(Buffer.from(message), getHexStringBytes(sig), keypair.publicKey))
503+
const sig = signatures[getBytesHexString(keypair.publicKey)];
504+
if (
505+
!sig ||
506+
!nacl.sign.detached.verify(
507+
Buffer.from(message),
508+
getHexStringBytes(sig),
509+
keypair.publicKey,
510+
)
511+
)
502512
return err(IErrorInternal.UnableToVerifyMessage);
503513
}
504514
return ok(true);
@@ -518,33 +528,32 @@ export class mgmtClient {
518528
}
519529

520530
/**
521-
* Save keypairs to localStorage. (Browser)
522-
*
523-
* @export
524-
* @param {string} keypairs IKeypairEncrypted[] flattened to a string
525-
* @return {*} {void} address of saved keypair
526-
*/
531+
* Save keypairs to localStorage. (Browser)
532+
*
533+
* @export
534+
* @param {string} keypairs IKeypairEncrypted[] flattened to a string
535+
* @return {*} {void} address of saved keypair
536+
*/
527537
public saveKeypairs(keypairs: IKeypairEncrypted[]): IResult<void> {
528538
if (!keypairs || typeof window !== 'undefined') {
529539
const flattened = JSON.stringify(keypairs);
530540
window.localStorage.setItem(KEYPAIR_LOCAL_STORAGE, flattened);
531-
return ok(undefined)
541+
return ok(undefined);
532542
}
533-
return err(IErrorInternal.UnableToSaveKeypairLocal)
543+
return err(IErrorInternal.UnableToSaveKeypairLocal);
534544
}
535545

536546
/**
537-
* Save keypairs to localStorage. (Browser)
538-
*
539-
* @export
540-
* @return {*} {IKeypairEncrypted[]}
541-
*/
547+
* Save keypairs to localStorage. (Browser)
548+
*
549+
* @export
550+
* @return {*} {IKeypairEncrypted[]}
551+
*/
542552
public getKeypairs(): IResult<IKeypairEncrypted[]> {
543553
let result = null;
544554
if (typeof window !== 'undefined')
545555
result = window.localStorage.getItem(KEYPAIR_LOCAL_STORAGE);
546-
if (result != null)
547-
return ok(JSON.parse(result))
548-
return err(IErrorInternal.UnableToGetLocalKeypair)
556+
if (result != null) return ok(JSON.parse(result));
557+
return err(IErrorInternal.UnableToGetLocalKeypair);
549558
}
550559
}

src/tests/__tests__/ablock.service.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ beforeEach(() => {
88
});
99

1010
test('init wallet without optional config fields', async () => {
11-
1211
const config = {
1312
mempoolHost: 'http://49.12.234.10:3003',
1413
passphrase: '',
@@ -60,7 +59,7 @@ test('handles key-pair re-generation from wallet seed phrase', async () => {
6059
'28a7de5c30f8271be690db7a979e1be33d31f6b6aebaa3c82888354ba214c24d',
6160
];
6261

63-
await ablockInstance.fromSeed(SEED, { passphrase: '' }, true,);
62+
await ablockInstance.fromSeed(SEED, { passphrase: '' }, true);
6463

6564
const foundAddresses = await ablockInstance.regenAddresses(SEED, utxoAddressList, 6);
6665

@@ -107,7 +106,7 @@ test('sign message with given keypairs', async () => {
107106

108107
expect(signatures).toBeDefined();
109108

110-
const result = ablockInstance.verifyMessage(MSG, signatures!, keypairs)
109+
const result = ablockInstance.verifyMessage(MSG, signatures!, keypairs);
111110

112111
expect(result.status).toBe('success');
113112

@@ -117,6 +116,6 @@ test('sign message with given keypairs', async () => {
117116

118117
const keypairs1 = [kp!, kp2!];
119118

120-
const result1 = ablockInstance.verifyMessage(MSG, signatures!, keypairs1)
119+
const result1 = ablockInstance.verifyMessage(MSG, signatures!, keypairs1);
121120
expect(result1.status).toBe('error');
122121
});

src/tests/__tests__/key.mgmt.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ test('derives deterministic signable keypairs through ed25519, via seed', () =>
9494
}
9595
});
9696

97-
// NOTE: This test corresponds with `test_construct_valid_addresses` in Chain
97+
// NOTE: This test corresponds with `test_construct_valid_addresses` in Chain
9898
test('generates a valid payment address with the temporary address structure', () => {
9999
const actual = [
100100
keyMgmt

0 commit comments

Comments
 (0)