@wishknish/knishio-client-js 0.5.2 → 0.6.1
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.
- package/README.md +207 -274
- package/dist/client.iife.js +533 -0
- package/package.json +37 -79
- package/src/.babelrc +0 -22
- package/src/Atom.js +171 -132
- package/src/AtomMeta.js +76 -50
- package/src/AuthToken.js +38 -47
- package/src/KnishIOClient.js +934 -987
- package/src/Meta.js +15 -17
- package/src/Molecule.js +423 -494
- package/src/PolicyMeta.js +32 -41
- package/src/TokenUnit.js +30 -32
- package/src/Wallet.js +275 -265
- package/src/exception/AtomIndexException.js +4 -8
- package/src/exception/AtomsMissingException.js +4 -6
- package/src/exception/AuthorizationRejectedException.js +4 -5
- package/src/exception/BalanceInsufficientException.js +4 -8
- package/src/exception/BaseException.js +6 -8
- package/src/exception/BatchIdException.js +5 -7
- package/src/exception/CodeException.js +4 -8
- package/src/{libraries/ApolloLink/HttpLink.js → exception/DecryptionKeyException.js} +12 -15
- package/src/exception/InvalidResponseException.js +4 -5
- package/src/exception/MetaMissingException.js +4 -6
- package/src/exception/MolecularHashMismatchException.js +4 -6
- package/src/exception/MolecularHashMissingException.js +4 -5
- package/src/exception/NegativeAmountException.js +4 -5
- package/src/exception/PolicyInvalidException.js +4 -4
- package/src/exception/SignatureMalformedException.js +4 -5
- package/src/exception/SignatureMismatchException.js +4 -5
- package/src/exception/StackableUnitAmountException.js +4 -5
- package/src/exception/StackableUnitDecimalsException.js +4 -5
- package/src/exception/TransferBalanceException.js +4 -5
- package/src/exception/TransferMalformedException.js +4 -5
- package/src/exception/TransferMismatchedException.js +4 -5
- package/src/exception/TransferRemainderException.js +4 -5
- package/src/exception/TransferToSelfException.js +4 -5
- package/src/exception/TransferUnbalancedException.js +4 -5
- package/src/exception/UnauthenticatedException.js +4 -5
- package/src/{libraries/ApolloLink/AuthLink.js → exception/WalletCredentialException.js} +12 -40
- package/src/exception/WalletShadowException.js +4 -5
- package/src/exception/WrongTokenTypeException.js +4 -5
- package/src/exception/index.js +26 -26
- package/src/index.js +8 -10
- package/src/instance/Rules/Callback.js +91 -93
- package/src/instance/Rules/Condition.js +21 -23
- package/src/instance/Rules/Meta.js +13 -14
- package/src/instance/Rules/Rule.js +39 -43
- package/src/instance/Rules/exception/RuleArgumentException.js +4 -4
- package/src/libraries/CheckMolecule.js +253 -232
- package/src/libraries/Decimal.js +13 -17
- package/src/libraries/Dot.js +74 -48
- package/src/libraries/Hex.js +49 -54
- package/src/libraries/array.js +50 -41
- package/src/libraries/crypto.js +20 -27
- package/src/libraries/strings.js +58 -91
- package/src/libraries/urql/UrqlClientWrapper.js +166 -0
- package/src/mutation/Mutation.js +44 -25
- package/src/mutation/MutationActiveSession.js +12 -12
- package/src/mutation/MutationClaimShadowWallet.js +15 -17
- package/src/mutation/MutationCreateIdentifier.js +11 -12
- package/src/mutation/MutationCreateMeta.js +11 -12
- package/src/mutation/MutationCreateRule.js +11 -12
- package/src/mutation/MutationCreateToken.js +18 -13
- package/src/mutation/MutationCreateWallet.js +9 -11
- package/src/mutation/MutationDepositBufferToken.js +7 -9
- package/src/mutation/MutationLinkIdentifier.js +12 -14
- package/src/mutation/MutationProposeMolecule.js +24 -25
- package/src/mutation/MutationRequestAuthorization.js +9 -10
- package/src/mutation/MutationRequestAuthorizationGuest.js +12 -15
- package/src/mutation/MutationRequestTokens.js +11 -14
- package/src/mutation/MutationTransferTokens.js +11 -14
- package/src/mutation/MutationWithdrawBufferToken.js +7 -10
- package/src/query/Query.js +62 -36
- package/src/query/QueryActiveSession.js +11 -13
- package/src/query/QueryAtom.js +75 -76
- package/src/query/QueryBalance.js +11 -12
- package/src/query/QueryBatch.js +17 -14
- package/src/query/QueryBatchHistory.js +16 -13
- package/src/query/QueryContinuId.js +13 -10
- package/src/query/QueryMetaType.js +45 -57
- package/src/query/QueryMetaTypeViaAtom.js +49 -57
- package/src/query/QueryPolicy.js +11 -12
- package/src/query/QueryToken.js +11 -13
- package/src/query/QueryUserActivity.js +11 -13
- package/src/query/QueryWalletBundle.js +15 -47
- package/src/query/QueryWalletList.js +15 -16
- package/src/response/Response.js +29 -34
- package/src/response/ResponseActiveSession.js +6 -6
- package/src/response/ResponseAtom.js +29 -30
- package/src/response/ResponseAuthorizationGuest.js +17 -18
- package/src/response/ResponseBalance.js +12 -13
- package/src/response/ResponseClaimShadowWallet.js +1 -1
- package/src/response/ResponseContinuId.js +21 -22
- package/src/response/ResponseCreateIdentifier.js +1 -1
- package/src/response/ResponseCreateMeta.js +1 -1
- package/src/response/ResponseCreateRule.js +1 -1
- package/src/response/ResponseCreateToken.js +1 -1
- package/src/response/ResponseCreateWallet.js +1 -1
- package/src/response/ResponseLinkIdentifier.js +9 -10
- package/src/response/ResponseMetaBatch.js +6 -8
- package/src/response/ResponseMetaType.js +19 -20
- package/src/response/ResponseMetaTypeViaAtom.js +19 -19
- package/src/response/ResponsePolicy.js +14 -15
- package/src/response/ResponseProposeMolecule.js +27 -30
- package/src/response/ResponseQueryActiveSession.js +20 -23
- package/src/response/ResponseQueryUserActivity.js +11 -12
- package/src/response/ResponseRequestAuthorization.js +11 -16
- package/src/response/ResponseRequestAuthorizationGuest.js +18 -21
- package/src/response/ResponseRequestTokens.js +1 -1
- package/src/response/ResponseTransferTokens.js +8 -9
- package/src/response/ResponseWalletBundle.js +16 -17
- package/src/response/ResponseWalletList.js +44 -47
- package/src/subscribe/ActiveSessionSubscribe.js +5 -6
- package/src/subscribe/ActiveWalletSubscribe.js +5 -6
- package/src/subscribe/CreateMoleculeSubscribe.js +5 -5
- package/src/subscribe/Subscribe.js +26 -26
- package/src/subscribe/WalletStatusSubscribe.js +5 -6
- package/src/versions/HashAtom.js +78 -0
- package/src/versions/Version4.js +34 -0
- package/src/versions/index.js +5 -0
- package/dist/client.umd.js +0 -453
- package/src/httpClient/ApolloClient.js +0 -245
- package/src/libraries/ApolloLink/CipherLink.js +0 -117
- package/src/libraries/ApolloLink/Client.js +0 -231
- package/src/libraries/ApolloLink/PusherLink.js +0 -234
- package/src/libraries/ApolloLink/handler.js +0 -106
- package/src/libraries/Base58.js +0 -71
- package/src/libraries/Base64.js +0 -40
- package/src/libraries/BaseX.js +0 -91
- package/src/libraries/Soda.js +0 -93
- package/src/query/QueryMetaInstance.js +0 -99
- package/src/test/Test.js +0 -670
- package/src/test/TestTokenUnit.js +0 -340
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
(
|
|
3
|
-
(/(
|
|
4
|
-
(//(
|
|
5
|
-
(///(
|
|
6
|
-
(/////(
|
|
7
|
-
(//////( )
|
|
8
|
-
(////////( (/)
|
|
9
|
-
(////////( (///)
|
|
10
|
-
(//////////( (////)
|
|
11
|
-
(//////////( (//////)
|
|
12
|
-
(////////////( (///////)
|
|
13
|
-
(/////////////( (/////////)
|
|
14
|
-
(//////////////( (///////////)
|
|
15
|
-
(///////////////( (/////////////)
|
|
16
|
-
(////////////////( (//////////////)
|
|
17
|
-
((((((((((((((((((( (((((((((((((((
|
|
18
|
-
((((((((((((((((((( ((((((((((((((
|
|
19
|
-
((((((((((((((((((( ((((((((((((((
|
|
20
|
-
(((((((((((((((((((( (((((((((((((
|
|
21
|
-
(((((((((((((((((((( ((((((((((((
|
|
22
|
-
((((((((((((((((((( ((((((((((((
|
|
23
|
-
((((((((((((((((((( ((((((((((
|
|
24
|
-
((((((((((((((((((/ (((((((((
|
|
25
|
-
(((((((((((((((((( ((((((((
|
|
26
|
-
((((((((((((((((( (((((((
|
|
27
|
-
(((((((((((((((((( (((((
|
|
28
|
-
################# ##
|
|
29
|
-
################ #
|
|
30
|
-
################# ##
|
|
31
|
-
%################ ###
|
|
32
|
-
###############( ####
|
|
33
|
-
############### ####
|
|
34
|
-
############### ######
|
|
35
|
-
%#############( (#######
|
|
36
|
-
%############# #########
|
|
37
|
-
############( ##########
|
|
38
|
-
########### #############
|
|
39
|
-
######### ##############
|
|
40
|
-
%######
|
|
41
|
-
|
|
42
|
-
Powered by Knish.IO: Connecting a Decentralized World
|
|
43
|
-
|
|
44
|
-
Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
|
|
45
|
-
|
|
46
|
-
License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
47
|
-
*/
|
|
48
|
-
import {
|
|
49
|
-
ApolloLink,
|
|
50
|
-
Observable
|
|
51
|
-
} from '@apollo/client/core';
|
|
52
|
-
import Pusher from 'pusher-js';
|
|
53
|
-
import { parse } from 'uri-js';
|
|
54
|
-
import CodeException from '../../exception/CodeException';
|
|
55
|
-
import Dot from '../Dot';
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
class PusherLink extends ApolloLink {
|
|
59
|
-
|
|
60
|
-
// constructor( options ) {
|
|
61
|
-
constructor ( {
|
|
62
|
-
socketUri,
|
|
63
|
-
authEndpoint,
|
|
64
|
-
appKey = 'knishio'
|
|
65
|
-
} ) {
|
|
66
|
-
console.log( 'PusherLink::constructor()...' );
|
|
67
|
-
super();
|
|
68
|
-
|
|
69
|
-
this.socketUri = socketUri;
|
|
70
|
-
this.authEndpoint = authEndpoint;
|
|
71
|
-
this.appKey = appKey;
|
|
72
|
-
|
|
73
|
-
this.setAuthToken( '' );
|
|
74
|
-
this.setTransport( this.getSocketUri() );
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
*
|
|
79
|
-
* @param {string} socketUri
|
|
80
|
-
*/
|
|
81
|
-
setTransport ( socketUri ) {
|
|
82
|
-
|
|
83
|
-
console.log( `Connecting to socket endpoint ${ socketUri }...` );
|
|
84
|
-
|
|
85
|
-
const wsPath = parse( socketUri );
|
|
86
|
-
|
|
87
|
-
if ( ![ 'ws', 'wss' ].includes( wsPath.scheme ) ) {
|
|
88
|
-
throw new CodeException( 'Incorrect scheme for the socket' );
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
this.transport = new Pusher( this.appKey, {
|
|
92
|
-
auth: {
|
|
93
|
-
headers: {
|
|
94
|
-
'X-Auth-Token': this.getAuthToken(),
|
|
95
|
-
Accept: 'application/json'
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
wsHost: wsPath.host,
|
|
99
|
-
wsPort: wsPath.port,
|
|
100
|
-
forceTLS: wsPath.scheme === 'wss',
|
|
101
|
-
encrypted: true,
|
|
102
|
-
enabledTransports: [ wsPath.scheme ],
|
|
103
|
-
authEndpoint: this.authEndpoint
|
|
104
|
-
} );
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
disconnect () {
|
|
108
|
-
this.transport.disconnect();
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
*
|
|
113
|
-
* @param {string} name
|
|
114
|
-
* @returns {Channel|null}
|
|
115
|
-
*/
|
|
116
|
-
channel ( name ) {
|
|
117
|
-
return this.transport.channel( name ) || null;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
*
|
|
122
|
-
* @return {string}
|
|
123
|
-
*/
|
|
124
|
-
getAuthToken () {
|
|
125
|
-
return this.auth;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* @param {string} auth
|
|
130
|
-
*/
|
|
131
|
-
setAuthToken ( auth ) {
|
|
132
|
-
this.auth = auth;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* @return {string|null}
|
|
137
|
-
*/
|
|
138
|
-
getSocketUri () {
|
|
139
|
-
return this.socketUri;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
request ( operation, forward ) {
|
|
143
|
-
this.transport.config.auth.headers[ 'X-Auth-Token' ] = this.getAuthToken();
|
|
144
|
-
|
|
145
|
-
const subscribeObservable = new Observable( ( _observer ) => {
|
|
146
|
-
//
|
|
147
|
-
} );
|
|
148
|
-
|
|
149
|
-
// Capture the super method
|
|
150
|
-
const prevSubscribe = subscribeObservable.subscribe.bind( subscribeObservable );
|
|
151
|
-
|
|
152
|
-
// Override subscribe to return an `unsubscribe` object, see
|
|
153
|
-
// https://github.com/apollographql/subscriptions-transport-ws/blob/master/src/client.ts#L182-L212
|
|
154
|
-
subscribeObservable.subscribe = ( observerOrNext, onError, onComplete ) => {
|
|
155
|
-
prevSubscribe( observerOrNext, onError, onComplete );
|
|
156
|
-
|
|
157
|
-
const observer = getObserver( observerOrNext, onError, onComplete );
|
|
158
|
-
|
|
159
|
-
let subscriptionChannel;
|
|
160
|
-
|
|
161
|
-
forward( operation ).subscribe( {
|
|
162
|
-
next: ( data ) => {
|
|
163
|
-
// If the operation has the subscription channel, it's a subscription
|
|
164
|
-
subscriptionChannel = Dot.get( data, 'extensions.lighthouse_subscriptions.channel' );
|
|
165
|
-
|
|
166
|
-
// No subscription found in the response, pipe data through
|
|
167
|
-
if ( !subscriptionChannel ) {
|
|
168
|
-
observer.next( data );
|
|
169
|
-
observer.complete();
|
|
170
|
-
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
this.subscribeToChannel( subscriptionChannel, observer );
|
|
175
|
-
}
|
|
176
|
-
} );
|
|
177
|
-
|
|
178
|
-
// Return an object that will unsubscribe_if the query was a subscription
|
|
179
|
-
return {
|
|
180
|
-
closed: false,
|
|
181
|
-
unsubscribe: () => {
|
|
182
|
-
subscriptionChannel &&
|
|
183
|
-
this.unsubscribeFromChannel( subscriptionChannel );
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
return subscribeObservable;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
subscribeToChannel ( subscriptionChannel, observer ) {
|
|
192
|
-
this.transport
|
|
193
|
-
.subscribe( subscriptionChannel )
|
|
194
|
-
.bind( 'lighthouse-subscription', ( payload ) => {
|
|
195
|
-
if ( !payload.more ) {
|
|
196
|
-
this.unsubscribeFromChannel( subscriptionChannel );
|
|
197
|
-
|
|
198
|
-
observer.complete();
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const result = payload.result;
|
|
202
|
-
|
|
203
|
-
if ( result ) {
|
|
204
|
-
observer.next( result );
|
|
205
|
-
}
|
|
206
|
-
} );
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
unsubscribeFromChannel ( subscriptionChannel ) {
|
|
210
|
-
this.transport.unsubscribe( subscriptionChannel );
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// Turn `subscribe` arguments into an observer-like thing, see getObserver
|
|
215
|
-
// https://github.com/apollographql/subscriptions-transport-ws/blob/master/src/client.ts#L329-L343
|
|
216
|
-
function getObserver ( observerOrNext, onError, onComplete ) {
|
|
217
|
-
if ( typeof observerOrNext === 'function' ) {
|
|
218
|
-
// Duck-type an observer
|
|
219
|
-
return {
|
|
220
|
-
next: ( v ) => observerOrNext( v ),
|
|
221
|
-
error: ( e ) => onError && onError( e ),
|
|
222
|
-
complete: () => onComplete && onComplete()
|
|
223
|
-
};
|
|
224
|
-
} else {
|
|
225
|
-
// Make an object that calls to the given object, with safety checks
|
|
226
|
-
return {
|
|
227
|
-
next: ( v ) => observerOrNext.next && observerOrNext.next( v ),
|
|
228
|
-
error: ( e ) => observerOrNext.error && observerOrNext.error( e ),
|
|
229
|
-
complete: () => observerOrNext.complete && observerOrNext.complete()
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
export default PusherLink;
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
(
|
|
3
|
-
(/(
|
|
4
|
-
(//(
|
|
5
|
-
(///(
|
|
6
|
-
(/////(
|
|
7
|
-
(//////( )
|
|
8
|
-
(////////( (/)
|
|
9
|
-
(////////( (///)
|
|
10
|
-
(//////////( (////)
|
|
11
|
-
(//////////( (//////)
|
|
12
|
-
(////////////( (///////)
|
|
13
|
-
(/////////////( (/////////)
|
|
14
|
-
(//////////////( (///////////)
|
|
15
|
-
(///////////////( (/////////////)
|
|
16
|
-
(////////////////( (//////////////)
|
|
17
|
-
((((((((((((((((((( (((((((((((((((
|
|
18
|
-
((((((((((((((((((( ((((((((((((((
|
|
19
|
-
((((((((((((((((((( ((((((((((((((
|
|
20
|
-
(((((((((((((((((((( (((((((((((((
|
|
21
|
-
(((((((((((((((((((( ((((((((((((
|
|
22
|
-
((((((((((((((((((( ((((((((((((
|
|
23
|
-
((((((((((((((((((( ((((((((((
|
|
24
|
-
((((((((((((((((((/ (((((((((
|
|
25
|
-
(((((((((((((((((( ((((((((
|
|
26
|
-
((((((((((((((((( (((((((
|
|
27
|
-
(((((((((((((((((( (((((
|
|
28
|
-
################# ##
|
|
29
|
-
################ #
|
|
30
|
-
################# ##
|
|
31
|
-
%################ ###
|
|
32
|
-
###############( ####
|
|
33
|
-
############### ####
|
|
34
|
-
############### ######
|
|
35
|
-
%#############( (#######
|
|
36
|
-
%############# #########
|
|
37
|
-
############( ##########
|
|
38
|
-
########### #############
|
|
39
|
-
######### ##############
|
|
40
|
-
%######
|
|
41
|
-
|
|
42
|
-
Powered by Knish.IO: Connecting a Decentralized World
|
|
43
|
-
|
|
44
|
-
Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
|
|
45
|
-
|
|
46
|
-
License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
47
|
-
*/
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @param {Operation} operation
|
|
51
|
-
* @return {string}
|
|
52
|
-
*/
|
|
53
|
-
export function operationName ( operation ) {
|
|
54
|
-
const operationDefinition = operation.query
|
|
55
|
-
.definitions.find( definitionNode => definitionNode.kind === 'OperationDefinition' );
|
|
56
|
-
const fieldNode = operationDefinition.selectionSet
|
|
57
|
-
.selections.find( definitionNode => definitionNode.kind === 'Field' );
|
|
58
|
-
|
|
59
|
-
return fieldNode.name.value;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* @param {Operation} operation
|
|
64
|
-
* @return {string}
|
|
65
|
-
*/
|
|
66
|
-
export function operationType ( operation ) {
|
|
67
|
-
const operationDefinition = operation.query
|
|
68
|
-
.definitions.find( definitionNode => definitionNode.kind === 'OperationDefinition' );
|
|
69
|
-
|
|
70
|
-
return operationDefinition.operation;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function errorHandler ( {
|
|
74
|
-
graphQLErrors,
|
|
75
|
-
networkError,
|
|
76
|
-
operation,
|
|
77
|
-
forward,
|
|
78
|
-
response
|
|
79
|
-
} ) {
|
|
80
|
-
|
|
81
|
-
if ( graphQLErrors ) {
|
|
82
|
-
graphQLErrors.map( ( {
|
|
83
|
-
message,
|
|
84
|
-
debugMessage,
|
|
85
|
-
locations,
|
|
86
|
-
path
|
|
87
|
-
} ) => console.error(
|
|
88
|
-
`[GraphQL error]: ${ message }\r\n`,
|
|
89
|
-
` Message : ${ debugMessage }\r\n`,
|
|
90
|
-
` Path : ${ path }\r\n`,
|
|
91
|
-
` Location: ${ locations }\r\n`
|
|
92
|
-
) );
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if ( networkError ) {
|
|
96
|
-
const {
|
|
97
|
-
name,
|
|
98
|
-
statusCode,
|
|
99
|
-
result = {}
|
|
100
|
-
} = networkError;
|
|
101
|
-
console.error( `[Network error]: ${ name }, status code: ${ statusCode }` );
|
|
102
|
-
// if you would also like to retry automatically on
|
|
103
|
-
// network errors, we recommend that you use
|
|
104
|
-
// apollo-link-retry
|
|
105
|
-
}
|
|
106
|
-
}
|
package/src/libraries/Base58.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import base from 'base-x';
|
|
2
|
-
import { Buffer } from 'buffer';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export default class Base58 {
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @param {object} options
|
|
9
|
-
*/
|
|
10
|
-
constructor ( options = {} ) {
|
|
11
|
-
this.$options = Object.assign( { 'characters': 'GMP' }, options );
|
|
12
|
-
this.$encoder = base( this[ this.$options[ 'characters' ] ] || this[ 'GMP' ] );
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @param {Buffer} data
|
|
17
|
-
* @return {string}
|
|
18
|
-
*/
|
|
19
|
-
encode ( data ) {
|
|
20
|
-
return this.$encoder.encode( Buffer.from( data ) );
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @param {string} data
|
|
25
|
-
* @return {Buffer}
|
|
26
|
-
*/
|
|
27
|
-
decode ( data ) {
|
|
28
|
-
return this.$encoder.decode( data );
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @return {string}
|
|
33
|
-
* @constructor
|
|
34
|
-
*/
|
|
35
|
-
get GMP () {
|
|
36
|
-
return '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv';
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @return {string}
|
|
41
|
-
* @constructor
|
|
42
|
-
*/
|
|
43
|
-
get BITCOIN () {
|
|
44
|
-
return '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @return {string}
|
|
49
|
-
* @constructor
|
|
50
|
-
*/
|
|
51
|
-
get FLICKR () {
|
|
52
|
-
return '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @return {string}
|
|
57
|
-
* @constructor
|
|
58
|
-
*/
|
|
59
|
-
get RIPPLE () {
|
|
60
|
-
return 'rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz';
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* @return {string}
|
|
65
|
-
* @constructor
|
|
66
|
-
*/
|
|
67
|
-
get IPFS () {
|
|
68
|
-
return '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
}
|
package/src/libraries/Base64.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
decode as decodeBase64,
|
|
3
|
-
encode as encodeBase64
|
|
4
|
-
} from '@stablelib/base64';
|
|
5
|
-
import { Buffer } from 'buffer';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export default class Base64 {
|
|
9
|
-
/**
|
|
10
|
-
* @param {Buffer|ArrayBuffer|Uint8Array} data
|
|
11
|
-
* @return {string}
|
|
12
|
-
*/
|
|
13
|
-
static encode ( data ) {
|
|
14
|
-
return encodeBase64( data );
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @param {string} data
|
|
19
|
-
* @return {Buffer|ArrayBuffer|Uint8Array}
|
|
20
|
-
*/
|
|
21
|
-
static decode ( data ) {
|
|
22
|
-
return Buffer.from( decodeBase64( data ) );
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @param {Buffer|ArrayBuffer|Uint8Array} data
|
|
27
|
-
* @return {string}
|
|
28
|
-
*/
|
|
29
|
-
encode ( data ) {
|
|
30
|
-
return Base64.encode( data );
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @param {string} data
|
|
35
|
-
* @return {Buffer|ArrayBuffer|Uint8Array}
|
|
36
|
-
*/
|
|
37
|
-
decode ( data ) {
|
|
38
|
-
return Base64.decode( data );
|
|
39
|
-
}
|
|
40
|
-
}
|
package/src/libraries/BaseX.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import Base64 from './Base64';
|
|
2
|
-
import Base58 from './Base58';
|
|
3
|
-
import base from 'base-x';
|
|
4
|
-
import { Buffer } from 'buffer';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export default class BaseX {
|
|
8
|
-
/**
|
|
9
|
-
* @param {object} options
|
|
10
|
-
*/
|
|
11
|
-
constructor ( options = {} ) {
|
|
12
|
-
const basex = [ 'BASE2', 'BASE8', 'BASE11', 'BASE36', 'BASE62', 'BASE67' ];
|
|
13
|
-
const characters = [ 'BITCOIN', 'FLICKR', 'RIPPLE', 'IPFS' ];
|
|
14
|
-
const base64 = [ 'BASE64' ];
|
|
15
|
-
|
|
16
|
-
this.$options = Object.assign( { 'characters': 'BASE64' }, options );
|
|
17
|
-
this.$encoder = new Base58();
|
|
18
|
-
|
|
19
|
-
if ( base64.includes( this.$options.characters ) ) {
|
|
20
|
-
this.$encoder = new Base64();
|
|
21
|
-
} else if ( basex.includes( this.$options.characters ) ) {
|
|
22
|
-
this.$encoder = base( this[ this.$options.characters ] );
|
|
23
|
-
} else if ( characters.includes( this.$options.characters ) ) {
|
|
24
|
-
this.$encoder = new Base58( this.$options );
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @param {Buffer|ArrayBuffer|Uint8Array} data
|
|
30
|
-
* @return {string}
|
|
31
|
-
*/
|
|
32
|
-
encode ( data ) {
|
|
33
|
-
return this.$encoder.encode( Buffer.from( data ) );
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @param {string} data
|
|
38
|
-
* @return {Buffer|ArrayBuffer|Uint8Array}
|
|
39
|
-
*/
|
|
40
|
-
decode ( data ) {
|
|
41
|
-
return this.$encoder.decode( data );
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @return {string}
|
|
46
|
-
* @constructor
|
|
47
|
-
*/
|
|
48
|
-
get BASE2 () {
|
|
49
|
-
return '01';
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* @return {string}
|
|
54
|
-
* @constructor
|
|
55
|
-
*/
|
|
56
|
-
get BASE8 () {
|
|
57
|
-
return '01234567';
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* @return {string}
|
|
62
|
-
* @constructor
|
|
63
|
-
*/
|
|
64
|
-
get BASE11 () {
|
|
65
|
-
return '0123456789a';
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @return {string}
|
|
70
|
-
* @constructor
|
|
71
|
-
*/
|
|
72
|
-
get BASE36 () {
|
|
73
|
-
return '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* @return {string}
|
|
78
|
-
* @constructor
|
|
79
|
-
*/
|
|
80
|
-
get BASE62 () {
|
|
81
|
-
return '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* @return {string}
|
|
86
|
-
* @constructor
|
|
87
|
-
*/
|
|
88
|
-
get BASE67 () {
|
|
89
|
-
return 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.!~';
|
|
90
|
-
}
|
|
91
|
-
}
|
package/src/libraries/Soda.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import BaseX from './BaseX';
|
|
2
|
-
import { shake256 } from 'js-sha3';
|
|
3
|
-
import { box } from 'tweetnacl';
|
|
4
|
-
import { Buffer } from 'buffer';
|
|
5
|
-
import {
|
|
6
|
-
open,
|
|
7
|
-
seal
|
|
8
|
-
} from 'tweetnacl-sealedbox-js';
|
|
9
|
-
import {
|
|
10
|
-
decode as decodeUTF8,
|
|
11
|
-
encode as encodeUTF8
|
|
12
|
-
} from '@stablelib/utf8';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export default class Soda {
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @param {string|null} characters
|
|
19
|
-
*/
|
|
20
|
-
constructor ( characters = null ) {
|
|
21
|
-
this.base = new BaseX( { characters: characters || 'BASE64' } );
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @param {array|object} message
|
|
26
|
-
* @param {string} key
|
|
27
|
-
* @return {string}
|
|
28
|
-
*/
|
|
29
|
-
encrypt ( message, key ) {
|
|
30
|
-
return this.encode( seal( encodeUTF8( JSON.stringify( message ) ), this.decode( key ) ) );
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @param {string} decrypted
|
|
35
|
-
* @param {string} privateKey
|
|
36
|
-
* @param {string} publicKey
|
|
37
|
-
* @return {null|any}
|
|
38
|
-
*/
|
|
39
|
-
decrypt ( decrypted, privateKey, publicKey ) {
|
|
40
|
-
try {
|
|
41
|
-
return JSON.parse( decodeUTF8( open( this.decode( decrypted ), this.decode( publicKey ), this.decode( privateKey ) ) ) );
|
|
42
|
-
} catch ( e ) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
*
|
|
49
|
-
* @param {string} key
|
|
50
|
-
* @return {string}
|
|
51
|
-
*/
|
|
52
|
-
generatePrivateKey ( key ) {
|
|
53
|
-
const sponge = shake256.create( box.secretKeyLength * 8 );
|
|
54
|
-
sponge.update( key );
|
|
55
|
-
return this.base.encode( Buffer.from( sponge.digest() ) );
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @param {string} key
|
|
60
|
-
* @return {string}
|
|
61
|
-
*/
|
|
62
|
-
generatePublicKey ( key ) {
|
|
63
|
-
const boxKey = box.keyPair.fromSecretKey( this.decode( key ) );
|
|
64
|
-
return this.encode( boxKey.publicKey );
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* @param {string} key
|
|
69
|
-
* @return {string}
|
|
70
|
-
*/
|
|
71
|
-
shortHash ( key ) {
|
|
72
|
-
const sponge = shake256.create( 64 );
|
|
73
|
-
sponge.update( key );
|
|
74
|
-
return this.base.encode( Buffer.from( sponge.digest() ) );
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* @param {string} data
|
|
79
|
-
* @return {string|Buffer}
|
|
80
|
-
*/
|
|
81
|
-
decode ( data ) {
|
|
82
|
-
return this.base.decode( data );
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* @param {string|Buffer|Uint8Array} data
|
|
87
|
-
* @return {string}
|
|
88
|
-
*/
|
|
89
|
-
encode ( data ) {
|
|
90
|
-
return this.base.encode( data );
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
}
|