Skip to content

Commit f06e473

Browse files
author
Grégory Saive
authored
Merge branch 'master' into task/g41-add-alias-for-HashLockTransaction
2 parents b0617d5 + 5c76924 commit f06e473

File tree

18 files changed

+671
-77
lines changed

18 files changed

+671
-77
lines changed

.travis.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,17 @@ cache:
88
- "node_modules"
99
before_script:
1010
- npm run build
11-
script: npm run test:coveralls
11+
script:
12+
- npm run test:coveralls
13+
before_deploy:
14+
- npm install --global typedoc
15+
- typedoc --out ts-docs src
16+
deploy:
17+
provider: pages
18+
skip_cleanup: true
19+
keep-history: true
20+
local_dir: ts-docs
21+
github_token: $GITHUB_TOKEN
22+
on:
23+
branch: master
24+

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ with the NEM2 (a.k.a Catapult)
1616
- NodeJS 9.X.X
1717
- NodeJS 10.X.X
1818

19+
## Installation
20+
21+
```npm install nem2-sdk rxjs```
22+
1923
## Documentation and Getting Started
2024

2125
Get started and learn more about nem2-sdk-typescript-javascript, check the [official documentation][docs].
@@ -47,4 +51,4 @@ Licensed under the [Apache License 2.0](LICENSE)
4751
[self]: https://github.com/nemtech/nem2-sdk-typescript-javascript
4852
[docs]: http://nemtech.github.io/getting-started/setup-workstation.html
4953
[issues]: https://github.com/nemtech/nem2-sdk-typescript-javascript/issues
50-
[sdk-ref]: http://nemtech.github.io/nem2-sdk-typescript-javascript
54+
[sdk-ref]: http://nemtech.github.io/nem2-sdk-typescript-javascript

e2e/infrastructure/TransactionHttp.spec.ts

Lines changed: 303 additions & 25 deletions
Large diffs are not rendered by default.

package-lock.json

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
"typescript-require": "^0.2.9-1"
5151
},
5252
"dependencies": {
53+
"@types/crypto-js": "^3.1.43",
54+
"crypto-js": "^3.1.9-1",
5355
"js-joda": "^1.6.2",
5456
"nem2-library": "^0.9.5",
5557
"request": "^2.83.0",

src/infrastructure/Listener.ts

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export class Listener {
104104
this.webSocket.onerror = (err) => {
105105
console.log('WebSocket Error ');
106106
console.log(err);
107+
reject(err);
107108
};
108109
this.webSocket.onmessage = (msg) => {
109110
const message = JSON.parse(msg.data as string);
@@ -155,6 +156,17 @@ export class Listener {
155156
});
156157
}
157158

159+
/**
160+
* returns a boolean that repressents the open state
161+
* @returns a boolean
162+
*/
163+
public isOpen(): boolean {
164+
if(this.webSocket){
165+
return this.webSocket.readyState === WebSocket.OPEN;
166+
}
167+
return false;
168+
}
169+
158170
/**
159171
* Close web socket connection.
160172
* @returns void
@@ -189,7 +201,7 @@ export class Listener {
189201
share(),
190202
filter((_) => _.channelName === ListenerChannelName.block),
191203
filter((_) => _.message instanceof BlockInfo),
192-
map((_) => _.message as BlockInfo),);
204+
map((_) => _.message as BlockInfo));
193205
}
194206

195207
/**
@@ -206,7 +218,7 @@ export class Listener {
206218
filter((_) => _.channelName === ListenerChannelName.confirmedAdded),
207219
filter((_) => _.message instanceof Transaction),
208220
map((_) => _.message as Transaction),
209-
filter((_) => this.transactionFromAddress(_, address)),);
221+
filter((_) => this.transactionFromAddress(_, address)));
210222
}
211223

212224
/**
@@ -223,7 +235,7 @@ export class Listener {
223235
filter((_) => _.channelName === ListenerChannelName.unconfirmedAdded),
224236
filter((_) => _.message instanceof Transaction),
225237
map((_) => _.message as Transaction),
226-
filter((_) => this.transactionFromAddress(_, address)),);
238+
filter((_) => this.transactionFromAddress(_, address)));
227239
}
228240

229241
/**
@@ -239,7 +251,7 @@ export class Listener {
239251
return this.messageSubject.asObservable().pipe(
240252
filter((_) => _.channelName === ListenerChannelName.unconfirmedRemoved),
241253
filter((_) => typeof _.message === 'string'),
242-
map((_) => _.message as string),);
254+
map((_) => _.message as string));
243255
}
244256

245257
/**
@@ -256,7 +268,7 @@ export class Listener {
256268
filter((_) => _.channelName === ListenerChannelName.aggregateBondedAdded),
257269
filter((_) => _.message instanceof AggregateTransaction),
258270
map((_) => _.message as AggregateTransaction),
259-
filter((_) => this.transactionFromAddress(_, address)),);
271+
filter((_) => this.transactionFromAddress(_, address)));
260272
}
261273

262274
/**
@@ -272,7 +284,7 @@ export class Listener {
272284
return this.messageSubject.asObservable().pipe(
273285
filter((_) => _.channelName === ListenerChannelName.aggregateBondedRemoved),
274286
filter((_) => typeof _.message === 'string'),
275-
map((_) => _.message as string),);
287+
map((_) => _.message as string));
276288
}
277289

278290
/**
@@ -288,7 +300,7 @@ export class Listener {
288300
return this.messageSubject.asObservable().pipe(
289301
filter((_) => _.channelName === ListenerChannelName.status),
290302
filter((_) => _.message instanceof TransactionStatusError),
291-
map((_) => _.message as TransactionStatusError),);
303+
map((_) => _.message as TransactionStatusError));
292304
}
293305

294306
/**
@@ -304,7 +316,7 @@ export class Listener {
304316
return this.messageSubject.asObservable().pipe(
305317
filter((_) => _.channelName === ListenerChannelName.cosignature),
306318
filter((_) => _.message instanceof CosignatureSignedTransaction),
307-
map((_) => _.message as CosignatureSignedTransaction),);
319+
map((_) => _.message as CosignatureSignedTransaction));
308320
}
309321

310322
/**
@@ -320,6 +332,18 @@ export class Listener {
320332
this.webSocket.send(JSON.stringify(subscriptionMessage));
321333
}
322334

335+
/**
336+
* @internal
337+
* @param channel - Channel to unsubscribe
338+
*/
339+
private unsubscribeTo(channel: string) {
340+
const unsubscribeMessage = {
341+
uid: this.uid,
342+
unsubscribe: channel,
343+
};
344+
this.webSocket.send(JSON.stringify(unsubscribeMessage));
345+
}
346+
323347
/**
324348
* @internal
325349
* Filters if a transaction has been initiated or signed by an address

src/model/UInt64.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export class UInt64 {
3737
* @returns {UInt64}
3838
*/
3939
public static fromUint(value: number): UInt64 {
40+
if (value < 0) {
41+
throw new Error('Unsigned integer cannot be negative');
42+
}
4043
return new UInt64(uint64.fromUint(value));
4144
}
4245

src/model/mosaic/Mosaic.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export class Mosaic {
4141

4242
}
4343

44-
4544
/**
4645
* @internal
4746
* @returns {{amount: number[], id: number[]}}

src/model/mosaic/MosaicProperties.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class MosaicProperties {
6060
* The duration in blocks a mosaic will be available.
6161
* After the duration finishes mosaic is inactive and can be renewed.
6262
*/
63-
public readonly duration: UInt64,) {
63+
public readonly duration: UInt64) {
6464
let binaryFlags = '00' + (flags.lower >>> 0).toString(2);
6565
binaryFlags = binaryFlags.substr(binaryFlags.length - 3, 3);
6666
this.supplyMutable = binaryFlags[2] === '1';

src/model/transaction/HashType.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,32 @@
1616

1717
/**
1818
* Hash type. Supported types are:
19-
* 0: SHA3_512.
19+
* 0: Op_Sha3_256 (default).
20+
* 1: Op_Keccak_256 (ETH compatibility).
21+
* 2: Op_Hash_160 (first with SHA-256 and then with RIPEMD-160 (BTC compatibility))
22+
* 3: Op_Hash_256: input is hashed twice with SHA-256 (BTC compatibility)
2023
*/
2124
import {convert} from 'nem2-library';
2225

2326
export enum HashType {
24-
SHA3_512 = 0,
27+
Op_Sha3_256 = 0,
28+
Op_Keccak_256 = 1,
29+
Op_Hash_160 = 2,
30+
Op_Hash_256 = 3,
2531
}
2632

2733
export function HashTypeLengthValidator(hashType: HashType, input: string): boolean {
28-
if (hashType === HashType.SHA3_512 && convert.isHexString(input)) {
29-
return input.length === 128;
34+
if (convert.isHexString(input)) {
35+
switch (hashType) {
36+
case HashType.Op_Sha3_256:
37+
case HashType.Op_Hash_256:
38+
case HashType.Op_Keccak_256:
39+
return input.length === 64;
40+
case HashType.Op_Hash_160:
41+
return input.length === 40;
42+
default:
43+
break;
44+
}
3045
}
3146
return false;
3247
}

0 commit comments

Comments
 (0)