@steemit/steem-js 0.8.0 → 1.0.0

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.
Files changed (126) hide show
  1. package/README.md +202 -105
  2. package/dist/api/index.d.ts +128 -0
  3. package/dist/api/methods.d.ts +9 -0
  4. package/dist/api/rpc-auth.d.ts +43 -0
  5. package/dist/api/transports/base.d.ts +13 -0
  6. package/dist/api/transports/http.d.ts +9 -0
  7. package/dist/api/transports/index.d.ts +9 -0
  8. package/dist/api/transports/types.d.ts +35 -0
  9. package/dist/api/transports/ws.d.ts +18 -0
  10. package/dist/auth/ecc/index.d.ts +9 -0
  11. package/dist/auth/ecc/src/address.d.ts +13 -0
  12. package/dist/auth/ecc/src/aes.d.ts +16 -0
  13. package/dist/auth/ecc/src/brain_key.d.ts +1 -0
  14. package/dist/auth/ecc/src/ecdsa.d.ts +28 -0
  15. package/dist/auth/ecc/src/ecsignature.d.ts +19 -0
  16. package/dist/auth/ecc/src/enforce_types.d.ts +5 -0
  17. package/dist/auth/ecc/src/hash.d.ts +25 -0
  18. package/dist/auth/ecc/src/index.d.ts +9 -0
  19. package/dist/auth/ecc/src/key_private.d.ts +38 -0
  20. package/dist/auth/ecc/src/key_public.d.ts +41 -0
  21. package/dist/auth/ecc/src/key_utils.d.ts +9 -0
  22. package/dist/auth/ecc/src/signature.d.ts +18 -0
  23. package/dist/auth/ecc.d.ts +3 -0
  24. package/dist/auth/index.d.ts +48 -0
  25. package/dist/auth/key_classes.d.ts +3 -0
  26. package/dist/auth/serializer.d.ts +19 -0
  27. package/dist/broadcast/helpers.d.ts +11 -0
  28. package/dist/broadcast/index.d.ts +43 -0
  29. package/dist/broadcast/operations.d.ts +6 -0
  30. package/dist/config.d.ts +25 -0
  31. package/dist/crypto/index.d.ts +25 -0
  32. package/dist/formatter/index.d.ts +92 -0
  33. package/dist/index.cjs +25848 -0
  34. package/dist/index.cjs.map +1 -0
  35. package/dist/index.d.ts +30 -0
  36. package/dist/index.js +25812 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/index.umd.js +57513 -0
  39. package/dist/index.umd.js.map +1 -0
  40. package/dist/memo/index.d.ts +11 -0
  41. package/dist/operations/index.d.ts +44 -0
  42. package/dist/serializer/convert.d.ts +12 -0
  43. package/dist/serializer/index.d.ts +11 -0
  44. package/dist/serializer/number_utils.d.ts +8 -0
  45. package/dist/serializer/precision.d.ts +5 -0
  46. package/dist/serializer/types.d.ts +36 -0
  47. package/dist/types/index.d.ts +131 -0
  48. package/dist/types.d.ts +34 -0
  49. package/dist/utils/index.d.ts +8 -0
  50. package/dist/utils.d.ts +2 -0
  51. package/package.json +68 -87
  52. package/.dockerignore +0 -12
  53. package/.editorconfig +0 -20
  54. package/.eslintrc +0 -27
  55. package/LICENSE +0 -21
  56. package/circle.yml +0 -3
  57. package/config.json +0 -10
  58. package/dist/steem-tests.min.js +0 -4097
  59. package/dist/steem.min.js +0 -2089
  60. package/docker-webpack.config.js +0 -44
  61. package/lib/api/index.js +0 -315
  62. package/lib/api/methods.js +0 -428
  63. package/lib/api/rpc-auth.js +0 -135
  64. package/lib/api/transports/base.js +0 -31
  65. package/lib/api/transports/http.js +0 -157
  66. package/lib/api/transports/index.js +0 -13
  67. package/lib/api/transports/ws.js +0 -128
  68. package/lib/auth/ecc/index.js +0 -13
  69. package/lib/auth/ecc/src/address.js +0 -54
  70. package/lib/auth/ecc/src/aes.js +0 -148
  71. package/lib/auth/ecc/src/brain_key.js +0 -13
  72. package/lib/auth/ecc/src/ecdsa.js +0 -193
  73. package/lib/auth/ecc/src/ecsignature.js +0 -102
  74. package/lib/auth/ecc/src/enforce_types.js +0 -42
  75. package/lib/auth/ecc/src/hash.js +0 -58
  76. package/lib/auth/ecc/src/key_private.js +0 -159
  77. package/lib/auth/ecc/src/key_public.js +0 -143
  78. package/lib/auth/ecc/src/key_utils.js +0 -70
  79. package/lib/auth/ecc/src/signature.js +0 -135
  80. package/lib/auth/index.js +0 -113
  81. package/lib/auth/memo.js +0 -119
  82. package/lib/auth/serializer/index.js +0 -15
  83. package/lib/auth/serializer/src/ChainTypes.js +0 -87
  84. package/lib/auth/serializer/src/convert.js +0 -34
  85. package/lib/auth/serializer/src/error_with_cause.js +0 -27
  86. package/lib/auth/serializer/src/fast_parser.js +0 -57
  87. package/lib/auth/serializer/src/number_utils.js +0 -43
  88. package/lib/auth/serializer/src/object_id.js +0 -43
  89. package/lib/auth/serializer/src/operations.js +0 -695
  90. package/lib/auth/serializer/src/precision.js +0 -77
  91. package/lib/auth/serializer/src/serializer.js +0 -165
  92. package/lib/auth/serializer/src/template.js +0 -22
  93. package/lib/auth/serializer/src/types.js +0 -1085
  94. package/lib/auth/serializer/src/validation.js +0 -300
  95. package/lib/broadcast/helpers.js +0 -140
  96. package/lib/broadcast/index.js +0 -106
  97. package/lib/broadcast/operations.js +0 -255
  98. package/lib/browser.js +0 -25
  99. package/lib/config.js +0 -23
  100. package/lib/formatter.js +0 -163
  101. package/lib/index.js +0 -21
  102. package/lib/utils.js +0 -50
  103. package/node-18.dockerfile +0 -28
  104. package/test/Crypto.js +0 -100
  105. package/test/KeyFormats.js +0 -105
  106. package/test/all_types.js +0 -115
  107. package/test/api.test.js +0 -363
  108. package/test/broadcast.test.js +0 -231
  109. package/test/browser/BrowserTests.js +0 -55
  110. package/test/comment.test.js +0 -83
  111. package/test/hf20-accounts.test.js +0 -76
  112. package/test/hf21-sps.test.js +0 -78
  113. package/test/memo.test.js +0 -37
  114. package/test/number_utils.js +0 -28
  115. package/test/operations_test.js +0 -39
  116. package/test/promise-broadcast.test.js +0 -86
  117. package/test/reputation.test.js +0 -68
  118. package/test/smt.test.js +0 -347
  119. package/test/test-post.json +0 -13
  120. package/test/test.html +0 -13
  121. package/test/test_helper.js +0 -19
  122. package/test/types_test.js +0 -139
  123. package/test-github-workflow.bat +0 -19
  124. package/test-github-workflow.sh +0 -15
  125. package/webpack/makeConfig.js +0 -113
  126. package/webpack.config.js +0 -2
@@ -1,231 +0,0 @@
1
- import Promise from 'bluebird';
2
- import should from 'should';
3
- import steem from '../src';
4
-
5
- const username = process.env.STEEM_USERNAME || 'guest123';
6
- const password = process.env.STEEM_PASSWORD;
7
- const postingWif = password
8
- ? steem.auth.toWif(username, password, 'posting')
9
- : '5JRaypasxMx1L97ZUX7YuC5Psb5EAbF821kkAGtBj7xCJFQcbLg';
10
-
11
- describe('steem.broadcast:', () => {
12
- it('exists', () => {
13
- should.exist(steem.broadcast);
14
- });
15
-
16
- it('has generated methods', () => {
17
- should.exist(steem.broadcast.vote);
18
- should.exist(steem.broadcast.voteWith);
19
- should.exist(steem.broadcast.comment);
20
- should.exist(steem.broadcast.transfer);
21
- });
22
-
23
- it('has backing methods', () => {
24
- should.exist(steem.broadcast.send);
25
- });
26
-
27
- it('has promise methods', () => {
28
- should.exist(steem.broadcast.sendAsync);
29
- should.exist(steem.broadcast.voteAsync);
30
- should.exist(steem.broadcast.transferAsync);
31
- });
32
-
33
- describe('patching transaction with default global properties', () => {
34
- it('works', async () => {
35
- const tx = await steem.broadcast._prepareTransaction({
36
- extensions: [],
37
- operations: [['vote', {
38
- voter: 'yamadapc',
39
- author: 'yamadapc',
40
- permlink: 'test-1-2-3-4-5-6-7-9',
41
- }]],
42
- });
43
-
44
- tx.should.have.properties([
45
- 'expiration',
46
- 'ref_block_num',
47
- 'ref_block_prefix',
48
- 'extensions',
49
- 'operations',
50
- ]);
51
- });
52
- });
53
-
54
- describe('no blocks on chain', () => {
55
- it('works', async () => {
56
- const newAccountName = username + '-' + Math.floor(Math.random() * 10000);
57
- const keys = steem.auth.generateKeys(
58
- username, password, ['posting', 'active', 'owner', 'memo']);
59
-
60
- const oldGetDynamicGlobalProperties = steem.api.getDynamicGlobalPropertiesAsync;
61
- steem.api.getDynamicGlobalPropertiesAsync = () => Promise.resolve({
62
- time: '2019-04-14T21:30:56',
63
- last_irreversible_block_num: 32047459,
64
- });
65
-
66
- // If the block returned is `null`, then no blocks are on the chain yet.
67
- const oldGetBlockAsync = steem.api.getBlockAsync;
68
- steem.api.getBlockAsync = () => Promise.resolve(null);
69
-
70
- try {
71
- const tx = await steem.broadcast._prepareTransaction({
72
- extensions: [],
73
- operations: [[
74
- 'account_create',
75
- {
76
- fee: '0.000 STEEM',
77
- creator: username,
78
- new_account_name: newAccountName,
79
- owner: {
80
- weight_threshold: 1,
81
- account_auths: [],
82
- key_auths: [[keys.owner, 1]],
83
- },
84
- active: {
85
- weight_threshold: 1,
86
- account_auths: [],
87
- key_auths: [[keys.active, 1]],
88
- },
89
- posting: {
90
- weight_threshold: 1,
91
- account_auths: [],
92
- key_auths: [[keys.posting, 1]],
93
- },
94
- memo_key: keys.memo,
95
- json_metadata: '',
96
- extensions: [],
97
- }
98
- ]],
99
- });
100
-
101
- tx.should.have.properties([
102
- 'expiration',
103
- 'ref_block_num',
104
- 'ref_block_prefix',
105
- 'extensions',
106
- 'operations',
107
- ]);
108
- } finally {
109
- steem.api.getDynamicGlobalPropertiesAsync = oldGetDynamicGlobalProperties;
110
- steem.api.getBlockAsync = oldGetBlockAsync;
111
- }
112
- });
113
- });
114
-
115
- describe('downvoting', () => {
116
- it('works', async function() {
117
- this.timeout(10000);
118
- const tx = await steem.broadcast.voteAsync(
119
- postingWif,
120
- username,
121
- 'yamadapc',
122
- 'test-1-2-3-4-5-6-7-9',
123
- -1000
124
- );
125
- tx.should.have.properties([
126
- 'expiration',
127
- 'ref_block_num',
128
- 'ref_block_prefix',
129
- 'extensions',
130
- 'operations',
131
- 'signatures',
132
- ]);
133
- });
134
- });
135
-
136
- describe('voting', () => {
137
- beforeEach(function() {
138
- this.timeout(10000);
139
- return Promise.delay(3000);
140
- });
141
-
142
- it('works', async function() {
143
- this.timeout(10000);
144
- const tx = await steem.broadcast.voteAsync(
145
- postingWif,
146
- username,
147
- 'yamadapc',
148
- 'test-1-2-3-4-5-6-7-9',
149
- 10000
150
- );
151
-
152
- tx.should.have.properties([
153
- 'expiration',
154
- 'ref_block_num',
155
- 'ref_block_prefix',
156
- 'extensions',
157
- 'operations',
158
- 'signatures',
159
- ]);
160
- });
161
-
162
- it('works with callbacks', function(done) {
163
- this.timeout(10000);
164
- steem.broadcast.vote(
165
- postingWif,
166
- username,
167
- 'yamadapc',
168
- 'test-1-2-3-4-5-6-7-9',
169
- 5000,
170
- (err, tx) => {
171
- if (err) return done(err);
172
- tx.should.have.properties([
173
- 'expiration',
174
- 'ref_block_num',
175
- 'ref_block_prefix',
176
- 'extensions',
177
- 'operations',
178
- 'signatures',
179
- ]);
180
- done();
181
- }
182
- );
183
- });
184
- });
185
-
186
- describe('customJson', () => {
187
- before(function() {
188
- this.timeout(10000);
189
- return Promise.delay(3000);
190
- });
191
-
192
- it('works', async function() {
193
- this.timeout(10000);
194
- const tx = await steem.broadcast.customJsonAsync(
195
- postingWif,
196
- [],
197
- [username],
198
- 'follow',
199
- JSON.stringify([
200
- 'follow',
201
- {
202
- follower: username,
203
- following: 'fabien',
204
- what: ['blog'],
205
- },
206
- ])
207
- );
208
-
209
- tx.should.have.properties([
210
- 'expiration',
211
- 'ref_block_num',
212
- 'ref_block_prefix',
213
- 'extensions',
214
- 'operations',
215
- 'signatures',
216
- ]);
217
- });
218
- });
219
-
220
- describe('writeOperations', () => {
221
- it('receives a properly formatted error response', () => {
222
- const wif = steem.auth.toWif('username', 'password', 'posting');
223
- return steem.broadcast.voteAsync(wif, 'voter', 'author', 'permlink', 0).
224
- then(() => {
225
- throw new Error('writeOperation should have failed but it didn\'t');
226
- }, (e) => {
227
- should.exist(e.message);
228
- });
229
- });
230
- });
231
- });
@@ -1,55 +0,0 @@
1
- import assert from 'assert'
2
- import {PrivateKey, PublicKey} from 'shared/ecc'
3
- import {encode, decode} from 'shared/chain/memo'
4
- import {serverApiRecordEvent} from 'app/utils/ServerApiClient'
5
-
6
- export const browserTests = {}
7
-
8
- export default function runTests() {
9
- let rpt = ''
10
- let pass = true
11
- function it(name, fn) {
12
- console.log('Testing', name)
13
- rpt += 'Testing ' + name + '\n'
14
- try {
15
- fn()
16
- } catch(error) {
17
- console.error(error)
18
- pass = false
19
- rpt += error.stack + '\n\n'
20
- serverApiRecordEvent('client_error', error)
21
- }
22
- }
23
-
24
- let private_key, public_key, encodedMemo
25
- const wif = '5JdeC9P7Pbd1uGdFVEsJ41EkEnADbbHGq6p1BwFxm6txNBsQnsw'
26
- const pubkey = 'STM8m5UgaFAAYQRuaNejYdS8FVLVp9Ss3K1qAVk5de6F8s3HnVbvA'
27
-
28
- it('create private key', () => {
29
- private_key = PrivateKey.fromSeed('1')
30
- assert.equal(private_key.toWif(), wif)
31
- })
32
- it('supports WIF format', () => {
33
- assert(PrivateKey.fromWif(wif))
34
- })
35
- it('finds public from private key', () => {
36
- public_key = private_key.toPublicKey()
37
- // substring match ignore prefix
38
- assert.equal(public_key.toString(), pubkey, 'Public key did not match')
39
- })
40
- it('parses public key', () => {
41
- assert(PublicKey.fromString(public_key.toString()))
42
- })
43
- it('encrypts memo', () => {
44
- encodedMemo = encode(private_key, public_key, '#memo')
45
- assert(encodedMemo)
46
- })
47
- it('decripts memo', () => {
48
- const dec = decode(private_key, encodedMemo)
49
- if(dec !== '#memo') {
50
- console.error('Decoded memo did not match (memo encryption is unavailable)')
51
- browserTests.memo_encryption = false
52
- }
53
- })
54
- if(!pass) return rpt
55
- }
@@ -1,83 +0,0 @@
1
- import Promise from 'bluebird';
2
- import should from 'should';
3
- import steem from '../src';
4
- import pkg from '../package.json';
5
- import assert from 'assert'
6
-
7
- const username = process.env.STEEM_USERNAME || 'guest123';
8
- const password = process.env.STEEM_PASSWORD;
9
- const postingWif = password
10
- ? steem.auth.toWif(username, password, 'posting')
11
- : '5JRaypasxMx1L97ZUX7YuC5Psb5EAbF821kkAGtBj7xCJFQcbLg';
12
-
13
- describe('steem.broadcast:', () => {
14
-
15
- describe('comment with options', () => {
16
- before(function() {
17
- this.timeout(10000);
18
- return Promise.delay(3000);
19
- });
20
-
21
- it('works', async function() {
22
- this.timeout(10000);
23
- const permlink = steem.formatter.commentPermlink('siol', 'test');
24
- const operations = [
25
- ['comment',
26
- {
27
- parent_author: 'siol',
28
- parent_permlink: 'test',
29
- author: username,
30
- permlink,
31
- title: 'Test',
32
- body: `This is a test using Steem.js v${pkg.version}.`,
33
- json_metadata : JSON.stringify({
34
- tags: ['test'],
35
- app: `steemjs/${pkg.version}`
36
- })
37
- }
38
- ],
39
- ['comment_options', {
40
- author: username,
41
- permlink,
42
- max_accepted_payout: '1000000.000 SBD',
43
- percent_steem_dollars: 10000,
44
- allow_votes: true,
45
- allow_curation_rewards: true,
46
- extensions: [
47
- [0, {
48
- beneficiaries: [
49
- { account: 'good-karma', weight: 2000 },
50
- { account: 'null', weight: 5000 }
51
- ]
52
- }]
53
- ]
54
- }]
55
- ];
56
-
57
- const tx = await steem.broadcast.sendAsync(
58
- { operations, extensions: [] },
59
- { posting: postingWif }
60
- );
61
-
62
- tx.should.have.properties([
63
- 'expiration',
64
- 'ref_block_num',
65
- 'ref_block_prefix',
66
- 'extensions',
67
- 'operations',
68
- 'signatures',
69
- ]);
70
- });
71
- });
72
- });
73
-
74
- describe('commentPermLink:', () => {
75
- it('does not return dots', () => {
76
- var commentPermlink = steem.formatter.commentPermlink(
77
- 'foo.bar',
78
- 'the-first-physical-foo-bar-ready-to-be-shipped'
79
- );
80
- console.log(commentPermlink);
81
- assert.equal(-1, commentPermlink.indexOf('.'));
82
- });
83
- });
@@ -1,76 +0,0 @@
1
- import Promise from 'bluebird';
2
- import should from 'should';
3
- import steem from '../src';
4
-
5
- const username = process.env.STEEM_USERNAME || 'guest123';
6
- const password = process.env.STEEM_PASSWORD;
7
- const activeWif = steem.auth.toWif(username, password, 'active');
8
-
9
- describe('steem.hf20-accounts:', () => {
10
- it('has generated methods', () => {
11
- should.exist(steem.broadcast.claimAccount);
12
- should.exist(steem.broadcast.createClaimedAccount);
13
- });
14
-
15
- it('has promise methods', () => {
16
- should.exist(steem.broadcast.claimAccountAsync);
17
- should.exist(steem.broadcast.createClaimedAccountAsync);
18
- });
19
-
20
-
21
- describe('claimAccount', () => {
22
-
23
- /* Skip these tests. Steem-js test infrastructure not set up for testing active auths
24
- Blocked by Steem issue #3546
25
- it('signs and verifies auth', function(done) {
26
- let tx = {
27
- 'operations': [[
28
- 'claim_account', {
29
- 'creator': username,
30
- 'fee': '0.000 STEEM'}]]
31
- }
32
-
33
- steem.api.callAsync('condenser_api.get_version', []).then((result) => {
34
- if(result['blockchain_version'] < '0.22.0') return done();
35
-
36
- steem.broadcast._prepareTransaction(tx).then(function(tx){
37
- tx = steem.auth.signTransaction(tx, [activeWif]);
38
- steem.api.verifyAuthorityAsync(tx).then(
39
- (result) => {result.should.equal(true); done();},
40
- (err) => {done(err);}
41
- );
42
- });
43
- });
44
-
45
- });
46
-
47
- it('claims and creates account', function(done) {
48
- this.skip(); // (!) need test account with enough RC
49
-
50
- steem.api.callAsync('condenser_api.get_version', []).then((result) => {
51
- if(result['blockchain_version'] < '0.22.0') return done();
52
-
53
- steem.broadcast.claimAccountAsync(activeWif, username, '0.000 STEEM', []).then((result) => {
54
- let newAccountName = username + '-' + Math.floor(Math.random() * 10000);
55
- let keys = steem.auth.generateKeys(
56
- username, password, ['posting', 'active', 'owner', 'memo']);
57
-
58
- steem.broadcast.createClaimedAccountAsync(
59
- activeWif,
60
- username,
61
- newAccountName,
62
- keys['owner'],
63
- keys['active'],
64
- keys['posting'],
65
- keys['memo'],
66
- {}, []
67
- ).then((result) => {
68
- should.exist(result);
69
- done();
70
- }, (err) => {done(err)});
71
- }, (err) => {done(err)});
72
- });
73
- });
74
- */
75
- });
76
- });
@@ -1,78 +0,0 @@
1
- import assert from "assert"
2
- import Promise from 'bluebird';
3
- import should from 'should';
4
- import steem from '../src';
5
-
6
- const username = process.env.STEEM_USERNAME || 'guest123';
7
- const password = process.env.STEEM_PASSWORD;
8
- const activeWif = steem.auth.toWif(username, password, 'active');
9
-
10
- describe('steem.hf21-accounts:', () => {
11
- it('has generated methods', () => {
12
- should.exist(steem.broadcast.createProposal);
13
- should.exist(steem.broadcast.updateProposalVotes);
14
- should.exist(steem.broadcast.removeProposal);
15
- });
16
-
17
- it('has promise methods', () => {
18
- should.exist(steem.broadcast.createProposalAsync);
19
- should.exist(steem.broadcast.updateProposalVotesAsync);
20
- should.exist(steem.broadcast.removeProposalAsync);
21
- });
22
-
23
- describe('create proposal ops', () => {
24
- /* Skip these tests. Steem-js test infrastructure not set up for testing active auths
25
- Blocked by Steem issue #3546
26
- it('signs and verifies create_proposal', function(done) {
27
- let permlink = 'test';
28
-
29
- let tx = {
30
- 'operations': [[
31
- 'create_proposal', {
32
- 'creator': username,
33
- 'receiver': username,
34
- 'start_date': '2019-09-01T00:00:00',
35
- 'end_date': '2019-10-01T00:00:00',
36
- 'daily_pay': '1.000 SBD',
37
- 'subject': 'testing',
38
- 'permlink': permlink
39
- }]]
40
- }
41
-
42
- steem.api.callAsync('condenser_api.get_version', []).then((result) => {
43
- if(result['blockchain_version'] < '0.22.0') return done();
44
- result.should.have.property('blockchain_version');
45
-
46
- steem.broadcast._prepareTransaction(tx).then(function(tx){
47
- tx = steem.auth.signTransaction(tx, [activeWif]);
48
- steem.api.verifyAuthorityAsync(tx).then(
49
- (result) => {result.should.equal(true); done();},
50
- (err) => {done(err);}
51
- );
52
- });
53
- });
54
- })
55
-
56
- it('signs and verifies update_proposal_votes', function(done) {
57
- let tx = {
58
- 'operations': [[
59
- 'update_proposal_votes', {
60
- 'voter': username,
61
- 'proposal_ids': [7],
62
- 'approve': true
63
- }]]
64
- }
65
-
66
- return done();
67
-
68
- steem.broadcast._prepareTransaction(tx).then(function(tx){
69
- tx = steem.auth.signTransaction(tx, [activeWif]);
70
- steem.api.verifyAuthorityAsync(tx).then(
71
- (result) => {result.should.equal(true); done();},
72
- (err) => {done(err);}
73
- );
74
- });
75
- })
76
- */
77
- });
78
- });
package/test/memo.test.js DELETED
@@ -1,37 +0,0 @@
1
- import assert from 'assert'
2
- import {encode, decode} from '../src/auth/memo';
3
- import {PrivateKey} from '../src/auth/ecc';
4
-
5
-
6
- const private_key = PrivateKey.fromSeed("")
7
- const public_key = private_key.toPublicKey()
8
-
9
- describe('steem.auth: memo', ()=> {
10
- it('plain text', () => {
11
- const plaintext1 = encode(null/*private_key*/, null/*public_key*/, 'memo')
12
- assert.equal(plaintext1, 'memo')
13
-
14
- const plaintext2 = decode(null/*private_key*/, plaintext1)
15
- assert.equal(plaintext2, 'memo')
16
- })
17
- it('encryption obj params', () => {
18
- const cypertext = encode(private_key, public_key, '#memo')
19
- const plaintext = decode(private_key, cypertext)
20
- assert.equal(plaintext, '#memo')
21
- })
22
- it('encryption string params', () => {
23
- const cypertext = encode(private_key.toWif(), public_key.toPublicKeyString(), '#memo2')
24
- const plaintext = decode(private_key.toWif(), cypertext)
25
- assert.equal(plaintext, '#memo2')
26
- })
27
- it('known encryption', () => {
28
- const base58 = '#HU6pdQ4Hh8cFrDVooekRPVZu4BdrhAe9RxrWrei2CwfAApAPdM4PT5mSV9cV3tTuWKotYQF6suyM4JHFBZz4pcwyezPzuZ2na7uwhRcLqFoqCam1VU3eCLjVNqcgUNbH3'
29
- const nonce = '1462976530069648'
30
- const text = '#爱'
31
-
32
- const cypertext = encode(private_key, public_key, text, nonce)
33
- assert.equal(cypertext, base58)
34
- const plaintext = decode(private_key, cypertext)
35
- assert.equal(plaintext, text)
36
- })
37
- })
@@ -1,28 +0,0 @@
1
- import assert from "assert"
2
- import { toImpliedDecimal, fromImpliedDecimal } from "../src/auth/serializer/src/number_utils"
3
-
4
- describe("steem.auth: Number utils", () => {
5
-
6
-
7
- it("to implied decimal", ()=> {
8
- assert.equal("1", toImpliedDecimal(1, 0))
9
- assert.equal("10", toImpliedDecimal(1, 1))
10
- assert.equal("100", toImpliedDecimal(1, 2))
11
- assert.equal("10", toImpliedDecimal(".1", 2))
12
- assert.equal("10", toImpliedDecimal("0.1", 2))
13
- assert.equal("10", toImpliedDecimal("00.1", 2))
14
- assert.equal("10", toImpliedDecimal("00.10", 2))
15
- assert.throws(()=> toImpliedDecimal("00.100", 2))
16
- assert.throws(()=> toImpliedDecimal(9007199254740991 + 1, 1))
17
- })
18
-
19
- it("from implied decimal", ()=> {
20
- assert.equal("1", fromImpliedDecimal(1, 0))
21
- assert.equal("0.1", fromImpliedDecimal(1, 1))
22
- assert.equal("0.01", fromImpliedDecimal(1, 2))
23
- // must have suffixing zeros
24
- assert.equal("0.100", fromImpliedDecimal(100, 3))
25
- })
26
-
27
-
28
- })
@@ -1,39 +0,0 @@
1
- var assert = require('assert');
2
- var types = require('../src/auth/serializer/src/types');
3
- var ops = require('../src/auth/serializer/src/operations');
4
-
5
- describe("steem.auth: operation test", ()=> {
6
-
7
- it("templates", ()=> {
8
- for(let op in ops) {
9
- switch(op) {
10
- case "operation" : continue
11
- }
12
- template(ops[op])
13
- }
14
- })
15
-
16
- it("account_create", ()=> {
17
- let tx = {"ref_block_num": 19297,"ref_block_prefix": 1608085982,"expiration": "2016-03-23T22:41:21","operations": [ ["account_create",{"fee": "0.000 STEEM","creator": "initminer","new_account_name": "scott","owner": {"weight_threshold": 1,"account_auths": [],"key_auths": [ ["STM7DTS62msowgpAZJBNRMStMUt5bfRA4hc9j5wjwU4vKhi3KFkKb",1 ]]},"active": {"weight_threshold": 1,"account_auths": [],"key_auths": [ ["STM8k1f8fvHxLrCTqMdRUJcK2rCE3y7SQBb8PremyadWvVWMeedZy",1 ]]},"posting": {"weight_threshold": 1,"account_auths": [],"key_auths": [ ["STM6DgpKJqoVGg7o6J1jdiP45xxbgoUg5VGzs96YBxX42NZu2bZea",1 ]]},"memo_key": "STM6ppNVEFmvBW4jEkzxXnGKuKuwYjMUrhz2WX1kHeGSchGdWJEDQ","json_metadata": ""} ]],"extensions": [], "signatures": []}
18
-
19
- let tx_hex = "614bde71d95f911bf3560109000000000000000003535445454d000009696e69746d696e65720573636f74740100000000010332757668fa45c2bc21447a2ff1dc2bbed9d9dda1616fd7b700255bd28e9d674a010001000000000103fb8900a262d51b908846be54fcf04b3a80d12ee749b9446f976b58b220ba4eed010001000000000102af4963d0f034043f4b4b0c99220e6a4b5d8b9cc71e5cd7d110f7602f3a0a11d1010002ff0de11ef55b998daf88047f1a00a60ed5dffb0c23c3279f8bd42a733845c5da000000"
20
-
21
- // 03 53 54 45 45 4d 0000
22
- assert.equal("STEEM", new Buffer.from("535445454d", "hex").toString())
23
- let tx_object1 = ops.signed_transaction.fromObject(tx)
24
- let tx_object2 = ops.signed_transaction.fromHex(tx_hex)
25
- assert.deepEqual(tx, ops.signed_transaction.toObject(tx_object1))
26
- assert.deepEqual(tx, ops.signed_transaction.toObject(tx_object2))
27
- assert.deepEqual(tx_hex, ops.signed_transaction.toHex(tx_object1))
28
- assert.deepEqual(tx_hex, ops.signed_transaction.toHex(tx_object2))
29
- })
30
-
31
- })
32
-
33
- function template(op) {
34
-
35
- assert(op.toObject({}, {use_default: true}))
36
- assert(op.toObject({}, {use_default: true, annotate: true}))
37
-
38
-
39
- }