js-sha3 0.10.0 → 0.12.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.
- package/CHANGELOG.md +11 -0
- package/LICENSE.txt +1 -1
- package/README.md +44 -3
- package/build/sha3.min.js +3 -3
- package/build/sha3.min.mjs +3 -3
- package/build/sha3.mjs +156 -16
- package/index.d.ts +102 -0
- package/package.json +3 -2
- package/src/sha3.js +141 -14
- package/src/sha3.mjs +14 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## v0.12.0 / 2026-07-18
|
|
4
|
+
### Added
|
|
5
|
+
- KMACXOF128 and KMACXOF256 (NIST SP 800-185)
|
|
6
|
+
|
|
7
|
+
## v0.11.0 / 2026-07-18
|
|
8
|
+
### Added
|
|
9
|
+
- TupleHash128, TupleHash256, TupleHashXOF128, and TupleHashXOF256 (NIST SP 800-185)
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
- KMAC repeated output reads after finalize
|
|
13
|
+
|
|
3
14
|
## v0.10.0 / 2026-07-17
|
|
4
15
|
### Added
|
|
5
16
|
- support ESM #42, #38
|
package/LICENSE.txt
CHANGED
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://coveralls.io/r/emn178/js-sha3?branch=master)
|
|
5
5
|
[](https://nodei.co/npm/js-sha3/)
|
|
6
6
|
|
|
7
|
-
A simple SHA-3 / Keccak /
|
|
7
|
+
A simple SHA-3 / Keccak / SHAKE / cSHAKE / KMAC / TupleHash hash function for JavaScript supports UTF-8 encoding.
|
|
8
8
|
|
|
9
9
|
## Notice
|
|
10
10
|
* v0.8.0+ will throw an error if try to update hash after finalize.
|
|
@@ -53,6 +53,12 @@ cshake128('Message to hash', 256, 'function name', 'customization');
|
|
|
53
53
|
cshake256('Message to hash', 512, 'function name', 'customization');
|
|
54
54
|
kmac128('key', 'Message to hash', 256, 'customization');
|
|
55
55
|
kmac256('key', 'Message to hash', 512, 'customization');
|
|
56
|
+
kmacxof128('key', 'Message to hash', 256, 'customization');
|
|
57
|
+
kmacxof256('key', 'Message to hash', 512, 'customization');
|
|
58
|
+
tuplehash128(['abc', 'd'], 256, 'customization');
|
|
59
|
+
tuplehash256(['abc', 'd'], 512, 'customization');
|
|
60
|
+
tuplehashxof128(['abc', 'd'], 256, 'customization');
|
|
61
|
+
tuplehashxof256(['abc', 'd'], 512, 'customization');
|
|
56
62
|
|
|
57
63
|
// Support ArrayBuffer output
|
|
58
64
|
var arrayBuffer = keccak224.arrayBuffer('Message to hash');
|
|
@@ -83,6 +89,29 @@ var hash = cshake128.create(256, 'function name', 'customization');
|
|
|
83
89
|
|
|
84
90
|
// specify kmac key, output bits and customization when creating
|
|
85
91
|
var hash = kmac128.create('key', 256, 'customization');
|
|
92
|
+
|
|
93
|
+
// TupleHash: a tuple contains zero or more input strings.
|
|
94
|
+
// One-shot and method-level update
|
|
95
|
+
tuplehash128(['abc', 'd'], 256, '');
|
|
96
|
+
tuplehash128.update(['abc', 'd'], 256, '').hex();
|
|
97
|
+
|
|
98
|
+
// Incremental complete inputs (each update is one tuple input string)
|
|
99
|
+
tuplehash128.create(256, '')
|
|
100
|
+
.update('abc')
|
|
101
|
+
.update('d')
|
|
102
|
+
.hex();
|
|
103
|
+
|
|
104
|
+
// Streaming a large input when its byte length is known in advance.
|
|
105
|
+
// beginInput + updateChunk; no endInput() is needed.
|
|
106
|
+
// Inputs are absorbed sequentially. TupleHash does not parallelize tuple inputs;
|
|
107
|
+
// use ParallelHash for parallel hashing of one large input.
|
|
108
|
+
var tupleHash = tuplehash128.create(256, '');
|
|
109
|
+
tupleHash.beginInput(3);
|
|
110
|
+
tupleHash.updateChunk([0x61, 0x62]);
|
|
111
|
+
tupleHash.updateChunk([0x63]);
|
|
112
|
+
tupleHash.beginInput(1);
|
|
113
|
+
tupleHash.updateChunk([0x64]);
|
|
114
|
+
tupleHash.hex();
|
|
86
115
|
```
|
|
87
116
|
### Node.js
|
|
88
117
|
If you use node.js, you should require the module first:
|
|
@@ -101,7 +130,13 @@ const {
|
|
|
101
130
|
cshake128,
|
|
102
131
|
cshake256,
|
|
103
132
|
kmac128,
|
|
104
|
-
kmac256
|
|
133
|
+
kmac256,
|
|
134
|
+
kmacxof128,
|
|
135
|
+
kmacxof256,
|
|
136
|
+
tuplehash128,
|
|
137
|
+
tuplehash256,
|
|
138
|
+
tuplehashxof128,
|
|
139
|
+
tuplehashxof256
|
|
105
140
|
} = require('js-sha3');
|
|
106
141
|
```
|
|
107
142
|
|
|
@@ -122,7 +157,13 @@ import {
|
|
|
122
157
|
cshake128,
|
|
123
158
|
cshake256,
|
|
124
159
|
kmac128,
|
|
125
|
-
kmac256
|
|
160
|
+
kmac256,
|
|
161
|
+
kmacxof128,
|
|
162
|
+
kmacxof256,
|
|
163
|
+
tuplehash128,
|
|
164
|
+
tuplehash256,
|
|
165
|
+
tuplehashxof128,
|
|
166
|
+
tuplehashxof256
|
|
126
167
|
} from 'js-sha3';
|
|
127
168
|
```
|
|
128
169
|
|
package/build/sha3.min.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* [js-sha3]{@link https://github.com/emn178/js-sha3}
|
|
3
3
|
*
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.12.0
|
|
5
5
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
6
|
-
* @copyright Chen, Yi-Cyuan 2015-
|
|
6
|
+
* @copyright Chen, Yi-Cyuan 2015-2026
|
|
7
7
|
* @license MIT
|
|
8
8
|
*/
|
|
9
|
-
!function(){"use strict";function t(t,e,r){this.blocks=[],this.s=[],this.padding=e,this.outputBits=r,this.reset=!0,this.finalized=!1,this.block=0,this.start=0,this.blockCount=1600-(t<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=r>>5,this.extraBytes=(31&r)>>3;for(var n=0;n<50;++n)this.s[n]=0}function e(e,r,n){t.call(this,e,r,n)}var r="input is invalid type",n="object"==typeof window,i=n?window:{};i.JS_SHA3_NO_WINDOW&&(n=!1);var o=!n&&"object"==typeof self;!i.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?i=global:o&&(i=self);for(var a=!i.JS_SHA3_NO_COMMON_JS&&"object"==typeof module&&module.exports,s="function"==typeof define&&define.amd,u=!i.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,f="0123456789abcdef".split(""),c=[4,1024,262144,67108864],h=[0,8,16,24],p=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],d=[224,256,384,512],l=[128,256],y=["hex","buffer","arrayBuffer","array","digest"],b={128:168,256:136},v=i.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return"[object Array]"===Object.prototype.toString.call(t)}:Array.isArray,A=!u||!i.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView?ArrayBuffer.isView:function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer},g=function(t){var e=typeof t;if("string"===e)return[t,!0];if("object"!==e||null===t)throw new Error(r);if(u&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!v(t)&&!A(t))throw new Error(r);return[t,!1]},B=function(t){return 0===g(t)[0].length},_=function(t){for(var e=[],r=0;r<t.length;++r)e[r]=t[r];return e},k=function(e,r,n){return function(i){return new t(e,r,e).update(i)[n]()}},w=function(e,r,n){return function(i,o){return new t(e,r,o).update(i)[n]()}},S=function(t,e,r){return function(e,n,i,o){return z["cshake"+t].update(e,n,i,o)[r]()}},C=function(t,e,r){return function(e,n,i,o){return z["kmac"+t].update(e,n,i,o)[r]()}},x=function(t,e,r,n){for(var i=0;i<y.length;++i){var o=y[i];t[o]=e(r,n,o)}return t},m=function(e,r){var n=k(e,r,"hex");return n.create=function(){return new t(e,r,e)},n.update=function(t){return n.create().update(t)},x(n,k,e,r)},O=[{name:"keccak",padding:[1,256,65536,16777216],bits:d,createMethod:m},{name:"sha3",padding:[6,1536,393216,100663296],bits:d,createMethod:m},{name:"shake",padding:[31,7936,2031616,520093696],bits:l,createMethod:function(e,r){var n=w(e,r,"hex");return n.create=function(n){return new t(e,r,n)},n.update=function(t,e){return n.create(e).update(t)},x(n,w,e,r)}},{name:"cshake",padding:c,bits:l,createMethod:function(e,r){var n=b[e],i=S(e,0,"hex");return i.create=function(i,o,a){return B(o)&&B(a)?z["shake"+e].create(i):new t(e,r,i).bytepad([o,a],n)},i.update=function(t,e,r,n){return i.create(e,r,n).update(t)},x(i,S,e,r)}},{name:"kmac",padding:c,bits:l,createMethod:function(t,r){var n=b[t],i=C(t,0,"hex");return i.create=function(i,o,a){return new e(t,r,o).bytepad(["KMAC",a],n).bytepad([i],n)},i.update=function(t,e,r,n){return i.create(t,r,n).update(e)},x(i,C,t,r)}}],z={},N=[],J=0;J<O.length;++J)for(var M=O[J],j=M.bits,E=0;E<j.length;++E){var H=M.name+"_"+j[E];if(N.push(H),z[H]=M.createMethod(j[E],M.padding),"sha3"!==M.name){var I=M.name+j[E];N.push(I),z[I]=z[H]}}t.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var e=g(t);t=e[0];for(var r,n,i=e[1],o=this.blocks,a=this.byteCount,s=t.length,u=this.blockCount,f=0,c=this.s;f<s;){if(this.reset)for(this.reset=!1,o[0]=this.block,r=1;r<u+1;++r)o[r]=0;if(i)for(r=this.start;f<s&&r<a;++f)(n=t.charCodeAt(f))<128?o[r>>2]|=n<<h[3&r++]:n<2048?(o[r>>2]|=(192|n>>6)<<h[3&r++],o[r>>2]|=(128|63&n)<<h[3&r++]):n<55296||n>=57344?(o[r>>2]|=(224|n>>12)<<h[3&r++],o[r>>2]|=(128|n>>6&63)<<h[3&r++],o[r>>2]|=(128|63&n)<<h[3&r++]):(n=65536+((1023&n)<<10|1023&t.charCodeAt(++f)),o[r>>2]|=(240|n>>18)<<h[3&r++],o[r>>2]|=(128|n>>12&63)<<h[3&r++],o[r>>2]|=(128|n>>6&63)<<h[3&r++],o[r>>2]|=(128|63&n)<<h[3&r++]);else for(r=this.start;f<s&&r<a;++f)o[r>>2]|=t[f]<<h[3&r++];if(this.lastByteIndex=r,r>=a){for(this.start=r-a,this.block=o[u],r=0;r<u;++r)c[r]^=o[r];R(c),this.reset=!0}else this.start=r}return this},t.prototype.encode=function(t,e){var r=255&t,n=1,i=[r];for(r=255&(t>>=8);r>0;)i.unshift(r),r=255&(t>>=8),++n;return e?i.push(n):i.unshift(n),this.update(i),i.length},t.prototype.encodeString=function(t){var e=g(t);t=e[0];var r=e[1],n=0,i=t.length;if(r)for(var o=0;o<t.length;++o){var a=t.charCodeAt(o);a<128?n+=1:a<2048?n+=2:a<55296||a>=57344?n+=3:(a=65536+((1023&a)<<10|1023&t.charCodeAt(++o)),n+=4)}else n=i;return n+=this.encode(8*n),this.update(t),n},t.prototype.bytepad=function(t,e){for(var r=this.encode(e),n=0;n<t.length;++n)r+=this.encodeString(t[n]);var i=(e-r%e)%e,o=[];return o.length=i,this.update(o),this},t.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,e=this.lastByteIndex,r=this.blockCount,n=this.s;if(t[e>>2]|=this.padding[3&e],this.lastByteIndex===this.byteCount)for(t[0]=t[r],e=1;e<r+1;++e)t[e]=0;for(t[r-1]|=2147483648,e=0;e<r;++e)n[e]^=t[e];R(n)}},t.prototype.toString=t.prototype.hex=function(){this.finalize();for(var t,e=this.blockCount,r=this.s,n=this.outputBlocks,i=this.extraBytes,o=0,a=0,s="";a<n;){for(o=0;o<e&&a<n;++o,++a)t=r[o],s+=f[t>>4&15]+f[15&t]+f[t>>12&15]+f[t>>8&15]+f[t>>20&15]+f[t>>16&15]+f[t>>28&15]+f[t>>24&15];a%e==0&&(r=_(r),R(r),o=0)}return i&&(t=r[o],s+=f[t>>4&15]+f[15&t],i>1&&(s+=f[t>>12&15]+f[t>>8&15]),i>2&&(s+=f[t>>20&15]+f[t>>16&15])),s},t.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,r=this.s,n=this.outputBlocks,i=this.extraBytes,o=0,a=0,s=this.outputBits>>3;t=i?new ArrayBuffer(n+1<<2):new ArrayBuffer(s);for(var u=new Uint32Array(t);a<n;){for(o=0;o<e&&a<n;++o,++a)u[a]=r[o];a%e==0&&(r=_(r),R(r))}return i&&(u[a]=r[o],t=t.slice(0,s)),t},t.prototype.buffer=t.prototype.arrayBuffer,t.prototype.digest=t.prototype.array=function(){this.finalize();for(var t,e,r=this.blockCount,n=this.s,i=this.outputBlocks,o=this.extraBytes,a=0,s=0,u=[];s<i;){for(a=0;a<r&&s<i;++a,++s)t=s<<2,e=n[a],u[t]=255&e,u[t+1]=e>>8&255,u[t+2]=e>>16&255,u[t+3]=e>>24&255;s%r==0&&(n=_(n),R(n))}return o&&(t=s<<2,e=n[a],u[t]=255&e,o>1&&(u[t+1]=e>>8&255),o>2&&(u[t+2]=e>>16&255)),u},(e.prototype=new t).finalize=function(){return this.encode(this.outputBits,!0),t.prototype.finalize.call(this)};var R=function(t){var e,r,n,i,o,a,s,u,f,c,h,d,l,y,b,v,A,g,B,_,k,w,S,C,x,m,O,z,N,J,M,j,E,H,I,R,F,U,D,V,W,Y,K,q,G,L,P,Q,T,X,Z,$,tt,et,rt,nt,it,ot,at,st,ut,ft,ct;for(n=0;n<48;n+=2)i=t[0]^t[10]^t[20]^t[30]^t[40],o=t[1]^t[11]^t[21]^t[31]^t[41],a=t[2]^t[12]^t[22]^t[32]^t[42],s=t[3]^t[13]^t[23]^t[33]^t[43],u=t[4]^t[14]^t[24]^t[34]^t[44],f=t[5]^t[15]^t[25]^t[35]^t[45],c=t[6]^t[16]^t[26]^t[36]^t[46],h=t[7]^t[17]^t[27]^t[37]^t[47],e=(d=t[8]^t[18]^t[28]^t[38]^t[48])^(a<<1|s>>>31),r=(l=t[9]^t[19]^t[29]^t[39]^t[49])^(s<<1|a>>>31),t[0]^=e,t[1]^=r,t[10]^=e,t[11]^=r,t[20]^=e,t[21]^=r,t[30]^=e,t[31]^=r,t[40]^=e,t[41]^=r,e=i^(u<<1|f>>>31),r=o^(f<<1|u>>>31),t[2]^=e,t[3]^=r,t[12]^=e,t[13]^=r,t[22]^=e,t[23]^=r,t[32]^=e,t[33]^=r,t[42]^=e,t[43]^=r,e=a^(c<<1|h>>>31),r=s^(h<<1|c>>>31),t[4]^=e,t[5]^=r,t[14]^=e,t[15]^=r,t[24]^=e,t[25]^=r,t[34]^=e,t[35]^=r,t[44]^=e,t[45]^=r,e=u^(d<<1|l>>>31),r=f^(l<<1|d>>>31),t[6]^=e,t[7]^=r,t[16]^=e,t[17]^=r,t[26]^=e,t[27]^=r,t[36]^=e,t[37]^=r,t[46]^=e,t[47]^=r,e=c^(i<<1|o>>>31),r=h^(o<<1|i>>>31),t[8]^=e,t[9]^=r,t[18]^=e,t[19]^=r,t[28]^=e,t[29]^=r,t[38]^=e,t[39]^=r,t[48]^=e,t[49]^=r,y=t[0],b=t[1],L=t[11]<<4|t[10]>>>28,P=t[10]<<4|t[11]>>>28,z=t[20]<<3|t[21]>>>29,N=t[21]<<3|t[20]>>>29,st=t[31]<<9|t[30]>>>23,ut=t[30]<<9|t[31]>>>23,Y=t[40]<<18|t[41]>>>14,K=t[41]<<18|t[40]>>>14,H=t[2]<<1|t[3]>>>31,I=t[3]<<1|t[2]>>>31,v=t[13]<<12|t[12]>>>20,A=t[12]<<12|t[13]>>>20,Q=t[22]<<10|t[23]>>>22,T=t[23]<<10|t[22]>>>22,J=t[33]<<13|t[32]>>>19,M=t[32]<<13|t[33]>>>19,ft=t[42]<<2|t[43]>>>30,ct=t[43]<<2|t[42]>>>30,et=t[5]<<30|t[4]>>>2,rt=t[4]<<30|t[5]>>>2,R=t[14]<<6|t[15]>>>26,F=t[15]<<6|t[14]>>>26,g=t[25]<<11|t[24]>>>21,B=t[24]<<11|t[25]>>>21,X=t[34]<<15|t[35]>>>17,Z=t[35]<<15|t[34]>>>17,j=t[45]<<29|t[44]>>>3,E=t[44]<<29|t[45]>>>3,C=t[6]<<28|t[7]>>>4,x=t[7]<<28|t[6]>>>4,nt=t[17]<<23|t[16]>>>9,it=t[16]<<23|t[17]>>>9,U=t[26]<<25|t[27]>>>7,D=t[27]<<25|t[26]>>>7,_=t[36]<<21|t[37]>>>11,k=t[37]<<21|t[36]>>>11,$=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,q=t[8]<<27|t[9]>>>5,G=t[9]<<27|t[8]>>>5,m=t[18]<<20|t[19]>>>12,O=t[19]<<20|t[18]>>>12,ot=t[29]<<7|t[28]>>>25,at=t[28]<<7|t[29]>>>25,V=t[38]<<8|t[39]>>>24,W=t[39]<<8|t[38]>>>24,w=t[48]<<14|t[49]>>>18,S=t[49]<<14|t[48]>>>18,t[0]=y^~v&g,t[1]=b^~A&B,t[10]=C^~m&z,t[11]=x^~O&N,t[20]=H^~R&U,t[21]=I^~F&D,t[30]=q^~L&Q,t[31]=G^~P&T,t[40]=et^~nt&ot,t[41]=rt^~it&at,t[2]=v^~g&_,t[3]=A^~B&k,t[12]=m^~z&J,t[13]=O^~N&M,t[22]=R^~U&V,t[23]=F^~D&W,t[32]=L^~Q&X,t[33]=P^~T&Z,t[42]=nt^~ot&st,t[43]=it^~at&ut,t[4]=g^~_&w,t[5]=B^~k&S,t[14]=z^~J&j,t[15]=N^~M&E,t[24]=U^~V&Y,t[25]=D^~W&K,t[34]=Q^~X&$,t[35]=T^~Z&tt,t[44]=ot^~st&ft,t[45]=at^~ut&ct,t[6]=_^~w&y,t[7]=k^~S&b,t[16]=J^~j&C,t[17]=M^~E&x,t[26]=V^~Y&H,t[27]=W^~K&I,t[36]=X^~$&q,t[37]=Z^~tt&G,t[46]=st^~ft&et,t[47]=ut^~ct&rt,t[8]=w^~y&v,t[9]=S^~b&A,t[18]=j^~C&m,t[19]=E^~x&O,t[28]=Y^~H&R,t[29]=K^~I&F,t[38]=$^~q&L,t[39]=tt^~G&P,t[48]=ft^~et&nt,t[49]=ct^~rt&it,t[0]^=p[n],t[1]^=p[n+1]};if(a)module.exports=z;else{for(J=0;J<N.length;++J)i[N[J]]=z[N[J]];s&&define(function(){return z})}}();
|
|
9
|
+
!function(){"use strict";function t(t,e,r){this.blocks=[],this.s=[],this.padding=e,this.outputBits=r,this.reset=!0,this.finalized=!1,this.block=0,this.start=0,this.blockCount=1600-(t<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=r>>5,this.extraBytes=(31&r)>>3;for(var n=0;n<50;++n)this.s[n]=0}function e(e,r,n,i){t.call(this,e,r,n),this.xof=i}function r(t,r,n,i){e.call(this,t,r,n,i),this.inputActive=!1,this.inputBytesRemaining=0}var n="input is invalid type",i="tuple input is incomplete",o="object"==typeof window,u=o?window:{};u.JS_SHA3_NO_WINDOW&&(o=!1);var a=!o&&"object"==typeof self;!u.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?u=global:a&&(u=self);for(var s=!u.JS_SHA3_NO_COMMON_JS&&"object"==typeof module&&module.exports,f="function"==typeof define&&define.amd,h=!u.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,c="0123456789abcdef".split(""),p=[4,1024,262144,67108864],d=[0,8,16,24],l=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],y=[224,256,384,512],g=[128,256],v=["hex","buffer","arrayBuffer","array","digest"],b={128:168,256:136},w=u.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return"[object Array]"===Object.prototype.toString.call(t)}:Array.isArray,A=!h||!u.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView?ArrayBuffer.isView:function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer},B=function(t){var e=typeof t;if("string"===e)return[t,!0];if("object"!==e||null===t)throw new Error(n);if(h&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!w(t)&&!A(t))throw new Error(n);return[t,!1]},k=function(t){return 0===B(t)[0].length},_=function(t){for(var e=[],r=0;r<t.length;++r)e[r]=t[r];return e},m=function(e,r,n){return function(i){return new t(e,r,e).update(i)[n]()}},x=function(e,r,n){return function(i,o){return new t(e,r,o).update(i)[n]()}},C=function(t,e,r){return function(e,n,i,o){return J["cshake"+t].update(e,n,i,o)[r]()}},S=function(t,e,r,n){return function(e,i,o,u){return J[(r?"kmacxof":"kmac")+t].update(e,i,o,u)[n]()}},M=function(t,e,r,n){return function(e,i,o){return J[(r?"tuplehashxof":"tuplehash")+t].update(e,i,o)[n]()}},z=function(t,e,r,n){for(var i=0;i<v.length;++i){var o=v[i];t[o]=e(r,n,o)}return t},E=function(e,r){var n=m(e,r,"hex");return n.create=function(){return new t(e,r,e)},n.update=function(t){return n.create().update(t)},z(n,m,e,r)},O=function(t,r,n){var i=b[t],o=S(t,0,n,"hex");return o.create=function(o,u,a){return new e(t,r,u,n).bytepad(["KMAC",a],i).bytepad([o],i)},o.update=function(t,e,r,n){return o.create(t,r,n).update(e)},z(o,function(t,e,r){return S(t,0,n,r)},t,r)},R=function(t,e,i){var o=b[t],u=M(t,0,i,"hex");return u.create=function(n,u){return new r(t,e,n,i).bytepad(["TupleHash",u],o)},u.update=function(t,e,r){if(!w(t))throw new Error(n);for(var i=u.create(e,r),o=0;o<t.length;++o)i.update(t[o]);return i},z(u,function(t,e,r){return M(t,0,i,r)},t,e)},N=[{name:"keccak",padding:[1,256,65536,16777216],bits:y,createMethod:E},{name:"sha3",padding:[6,1536,393216,100663296],bits:y,createMethod:E},{name:"shake",padding:[31,7936,2031616,520093696],bits:g,createMethod:function(e,r){var n=x(e,r,"hex");return n.create=function(n){return new t(e,r,n)},n.update=function(t,e){return n.create(e).update(t)},z(n,x,e,r)}},{name:"cshake",padding:p,bits:g,createMethod:function(e,r){var n=b[e],i=C(e,0,"hex");return i.create=function(i,o,u){return k(o)&&k(u)?J["shake"+e].create(i):new t(e,r,i).bytepad([o,u],n)},i.update=function(t,e,r,n){return i.create(e,r,n).update(t)},z(i,C,e,r)}},{name:"kmac",padding:p,bits:g,createMethod:function(t,e){return O(t,e,!1)}},{name:"kmacxof",padding:p,bits:g,createMethod:function(t,e){return O(t,e,!0)}},{name:"tuplehash",padding:p,bits:g,createMethod:function(t,e){return R(t,e,!1)}},{name:"tuplehashxof",padding:p,bits:g,createMethod:function(t,e){return R(t,e,!0)}}],J={},j=[],I=0;I<N.length;++I)for(var H=N[I],F=H.bits,U=0;U<F.length;++U){var D=H.name+"_"+F[U];if(j.push(D),J[D]=H.createMethod(F[U],H.padding),"sha3"!==H.name){var L=H.name+F[U];j.push(L),J[L]=J[D]}}t.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var e=B(t);t=e[0];for(var r,n,i=e[1],o=this.blocks,u=this.byteCount,a=t.length,s=this.blockCount,f=0,h=this.s;f<a;){if(this.reset)for(this.reset=!1,o[0]=this.block,r=1;r<s+1;++r)o[r]=0;if(i)for(r=this.start;f<a&&r<u;++f)(n=t.charCodeAt(f))<128?o[r>>2]|=n<<d[3&r++]:n<2048?(o[r>>2]|=(192|n>>6)<<d[3&r++],o[r>>2]|=(128|63&n)<<d[3&r++]):n<55296||n>=57344?(o[r>>2]|=(224|n>>12)<<d[3&r++],o[r>>2]|=(128|n>>6&63)<<d[3&r++],o[r>>2]|=(128|63&n)<<d[3&r++]):(n=65536+((1023&n)<<10|1023&t.charCodeAt(++f)),o[r>>2]|=(240|n>>18)<<d[3&r++],o[r>>2]|=(128|n>>12&63)<<d[3&r++],o[r>>2]|=(128|n>>6&63)<<d[3&r++],o[r>>2]|=(128|63&n)<<d[3&r++]);else for(r=this.start;f<a&&r<u;++f)o[r>>2]|=t[f]<<d[3&r++];if(this.lastByteIndex=r,r>=u){for(this.start=r-u,this.block=o[s],r=0;r<s;++r)h[r]^=o[r];V(h),this.reset=!0}else this.start=r}return this},t.prototype.encode=function(e,r){var n=255&e,i=1,o=[n];for(n=255&(e>>=8);n>0;)o.unshift(n),n=255&(e>>=8),++i;return r?o.push(i):o.unshift(i),t.prototype.update.call(this,o),o.length},t.prototype.encodeString=function(e){var r=B(e);e=r[0];var n=r[1],i=0,o=e.length;if(n)for(var u=0;u<e.length;++u){var a=e.charCodeAt(u);a<128?i+=1:a<2048?i+=2:a<55296||a>=57344?i+=3:(a=65536+((1023&a)<<10|1023&e.charCodeAt(++u)),i+=4)}else i=o;return i+=this.encode(8*i),t.prototype.update.call(this,e),i},t.prototype.bytepad=function(e,r){for(var n=this.encode(r),i=0;i<e.length;++i)n+=this.encodeString(e[i]);var o=(r-n%r)%r,u=[];return u.length=o,t.prototype.update.call(this,u),this},t.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,e=this.lastByteIndex,r=this.blockCount,n=this.s;if(t[e>>2]|=this.padding[3&e],this.lastByteIndex===this.byteCount)for(t[0]=t[r],e=1;e<r+1;++e)t[e]=0;for(t[r-1]|=2147483648,e=0;e<r;++e)n[e]^=t[e];V(n)}},t.prototype.toString=t.prototype.hex=function(){this.finalize();for(var t,e=this.blockCount,r=this.s,n=this.outputBlocks,i=this.extraBytes,o=0,u=0,a="";u<n;){for(o=0;o<e&&u<n;++o,++u)t=r[o],a+=c[t>>4&15]+c[15&t]+c[t>>12&15]+c[t>>8&15]+c[t>>20&15]+c[t>>16&15]+c[t>>28&15]+c[t>>24&15];u%e==0&&(r=_(r),V(r),o=0)}return i&&(t=r[o],a+=c[t>>4&15]+c[15&t],i>1&&(a+=c[t>>12&15]+c[t>>8&15]),i>2&&(a+=c[t>>20&15]+c[t>>16&15])),a},t.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,r=this.s,n=this.outputBlocks,i=this.extraBytes,o=0,u=0,a=this.outputBits>>3;t=i?new ArrayBuffer(n+1<<2):new ArrayBuffer(a);for(var s=new Uint32Array(t);u<n;){for(o=0;o<e&&u<n;++o,++u)s[u]=r[o];u%e==0&&(r=_(r),V(r))}return i&&(s[u]=r[o],t=t.slice(0,a)),t},t.prototype.buffer=t.prototype.arrayBuffer,t.prototype.digest=t.prototype.array=function(){this.finalize();for(var t,e,r=this.blockCount,n=this.s,i=this.outputBlocks,o=this.extraBytes,u=0,a=0,s=[];a<i;){for(u=0;u<r&&a<i;++u,++a)t=a<<2,e=n[u],s[t]=255&e,s[t+1]=e>>8&255,s[t+2]=e>>16&255,s[t+3]=e>>24&255;a%r==0&&(n=_(n),V(n))}return o&&(t=a<<2,e=n[u],s[t]=255&e,o>1&&(s[t+1]=e>>8&255),o>2&&(s[t+2]=e>>16&255)),s},(e.prototype=new t).finalize=function(){return this.finalized||this.encode(this.xof?0:this.outputBits,!0),t.prototype.finalize.call(this)},(r.prototype=new e).getMessageByteLength=function(t){var e=B(t);if(t=e[0],!e[1])return t.length;for(var r=0,n=0;n<t.length;++n){var i=t.charCodeAt(n);i<128?r+=1:i<2048?r+=2:i<55296||i>=57344?r+=3:(++n,r+=4)}return r},r.prototype.beginInput=function(t){if(this.inputActive)throw new Error(i);if("number"!=typeof t||!isFinite(t)||t<0||Math.floor(t)!==t||t>268435455)throw new Error("tuple input byte length is invalid");return this.encode(8*t,!1),0!==t&&(this.inputActive=!0,this.inputBytesRemaining=t),this},r.prototype._updateChunk=function(t,r){return e.prototype.update.call(this,t),this.inputBytesRemaining-=r,0===this.inputBytesRemaining&&(this.inputActive=!1),this},r.prototype.updateChunk=function(t){if(!this.inputActive)throw new Error("no active tuple input");var e=this.getMessageByteLength(t);if(e>this.inputBytesRemaining)throw new Error("tuple input exceeds declared length");return this._updateChunk(t,e)},r.prototype.update=function(t){var e=this.getMessageByteLength(t);return this.beginInput(e),this._updateChunk(t,e)},r.prototype.finalize=function(){if(this.inputActive)throw new Error(i);return e.prototype.finalize.call(this)};var V=function(t){var e,r,n,i,o,u,a,s,f,h,c,p,d,y,g,v,b,w,A,B,k,_,m,x,C,S,M,z,E,O,R,N,J,j,I,H,F,U,D,L,V,W,Y,K,T,q,G,P,Q,X,Z,$,tt,et,rt,nt,it,ot,ut,at,st,ft,ht;for(n=0;n<48;n+=2)i=t[0]^t[10]^t[20]^t[30]^t[40],o=t[1]^t[11]^t[21]^t[31]^t[41],u=t[2]^t[12]^t[22]^t[32]^t[42],a=t[3]^t[13]^t[23]^t[33]^t[43],s=t[4]^t[14]^t[24]^t[34]^t[44],f=t[5]^t[15]^t[25]^t[35]^t[45],h=t[6]^t[16]^t[26]^t[36]^t[46],c=t[7]^t[17]^t[27]^t[37]^t[47],e=(p=t[8]^t[18]^t[28]^t[38]^t[48])^(u<<1|a>>>31),r=(d=t[9]^t[19]^t[29]^t[39]^t[49])^(a<<1|u>>>31),t[0]^=e,t[1]^=r,t[10]^=e,t[11]^=r,t[20]^=e,t[21]^=r,t[30]^=e,t[31]^=r,t[40]^=e,t[41]^=r,e=i^(s<<1|f>>>31),r=o^(f<<1|s>>>31),t[2]^=e,t[3]^=r,t[12]^=e,t[13]^=r,t[22]^=e,t[23]^=r,t[32]^=e,t[33]^=r,t[42]^=e,t[43]^=r,e=u^(h<<1|c>>>31),r=a^(c<<1|h>>>31),t[4]^=e,t[5]^=r,t[14]^=e,t[15]^=r,t[24]^=e,t[25]^=r,t[34]^=e,t[35]^=r,t[44]^=e,t[45]^=r,e=s^(p<<1|d>>>31),r=f^(d<<1|p>>>31),t[6]^=e,t[7]^=r,t[16]^=e,t[17]^=r,t[26]^=e,t[27]^=r,t[36]^=e,t[37]^=r,t[46]^=e,t[47]^=r,e=h^(i<<1|o>>>31),r=c^(o<<1|i>>>31),t[8]^=e,t[9]^=r,t[18]^=e,t[19]^=r,t[28]^=e,t[29]^=r,t[38]^=e,t[39]^=r,t[48]^=e,t[49]^=r,y=t[0],g=t[1],q=t[11]<<4|t[10]>>>28,G=t[10]<<4|t[11]>>>28,z=t[20]<<3|t[21]>>>29,E=t[21]<<3|t[20]>>>29,at=t[31]<<9|t[30]>>>23,st=t[30]<<9|t[31]>>>23,W=t[40]<<18|t[41]>>>14,Y=t[41]<<18|t[40]>>>14,j=t[2]<<1|t[3]>>>31,I=t[3]<<1|t[2]>>>31,v=t[13]<<12|t[12]>>>20,b=t[12]<<12|t[13]>>>20,P=t[22]<<10|t[23]>>>22,Q=t[23]<<10|t[22]>>>22,O=t[33]<<13|t[32]>>>19,R=t[32]<<13|t[33]>>>19,ft=t[42]<<2|t[43]>>>30,ht=t[43]<<2|t[42]>>>30,et=t[5]<<30|t[4]>>>2,rt=t[4]<<30|t[5]>>>2,H=t[14]<<6|t[15]>>>26,F=t[15]<<6|t[14]>>>26,w=t[25]<<11|t[24]>>>21,A=t[24]<<11|t[25]>>>21,X=t[34]<<15|t[35]>>>17,Z=t[35]<<15|t[34]>>>17,N=t[45]<<29|t[44]>>>3,J=t[44]<<29|t[45]>>>3,x=t[6]<<28|t[7]>>>4,C=t[7]<<28|t[6]>>>4,nt=t[17]<<23|t[16]>>>9,it=t[16]<<23|t[17]>>>9,U=t[26]<<25|t[27]>>>7,D=t[27]<<25|t[26]>>>7,B=t[36]<<21|t[37]>>>11,k=t[37]<<21|t[36]>>>11,$=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,K=t[8]<<27|t[9]>>>5,T=t[9]<<27|t[8]>>>5,S=t[18]<<20|t[19]>>>12,M=t[19]<<20|t[18]>>>12,ot=t[29]<<7|t[28]>>>25,ut=t[28]<<7|t[29]>>>25,L=t[38]<<8|t[39]>>>24,V=t[39]<<8|t[38]>>>24,_=t[48]<<14|t[49]>>>18,m=t[49]<<14|t[48]>>>18,t[0]=y^~v&w,t[1]=g^~b&A,t[10]=x^~S&z,t[11]=C^~M&E,t[20]=j^~H&U,t[21]=I^~F&D,t[30]=K^~q&P,t[31]=T^~G&Q,t[40]=et^~nt&ot,t[41]=rt^~it&ut,t[2]=v^~w&B,t[3]=b^~A&k,t[12]=S^~z&O,t[13]=M^~E&R,t[22]=H^~U&L,t[23]=F^~D&V,t[32]=q^~P&X,t[33]=G^~Q&Z,t[42]=nt^~ot&at,t[43]=it^~ut&st,t[4]=w^~B&_,t[5]=A^~k&m,t[14]=z^~O&N,t[15]=E^~R&J,t[24]=U^~L&W,t[25]=D^~V&Y,t[34]=P^~X&$,t[35]=Q^~Z&tt,t[44]=ot^~at&ft,t[45]=ut^~st&ht,t[6]=B^~_&y,t[7]=k^~m&g,t[16]=O^~N&x,t[17]=R^~J&C,t[26]=L^~W&j,t[27]=V^~Y&I,t[36]=X^~$&K,t[37]=Z^~tt&T,t[46]=at^~ft&et,t[47]=st^~ht&rt,t[8]=_^~y&v,t[9]=m^~g&b,t[18]=N^~x&S,t[19]=J^~C&M,t[28]=W^~j&H,t[29]=Y^~I&F,t[38]=$^~K&q,t[39]=tt^~T&G,t[48]=ft^~et&nt,t[49]=ht^~rt&it,t[0]^=l[n],t[1]^=l[n+1]};if(s)module.exports=J;else{for(I=0;I<j.length;++I)u[j[I]]=J[j[I]];f&&define(function(){return J})}}();
|
package/build/sha3.min.mjs
CHANGED
|
@@ -2,8 +2,8 @@ var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?windo
|
|
|
2
2
|
/**
|
|
3
3
|
* [js-sha3]{@link https://github.com/emn178/js-sha3}
|
|
4
4
|
*
|
|
5
|
-
* @version 0.
|
|
5
|
+
* @version 0.12.0
|
|
6
6
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
7
|
-
* @copyright Chen, Yi-Cyuan 2015-
|
|
7
|
+
* @copyright Chen, Yi-Cyuan 2015-2026
|
|
8
8
|
* @license MIT
|
|
9
|
-
*/r=n,function(){var e="input is invalid type",n="object"==typeof window,o=n?window:{};o.JS_SHA3_NO_WINDOW&&(n=!1);var i=!n&&"object"==typeof self;!o.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?o=t:i&&(o=self);for(var a=!o.JS_SHA3_NO_COMMON_JS&&r.exports,s=!o.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,u="0123456789abcdef".split(""),f=[4,1024,262144,67108864],c=[0,8,16,24],h=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],p=[224,256,384,512],d=[128,256],l=["hex","buffer","arrayBuffer","array","digest"],y={128:168,256:136},k=o.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return"[object Array]"===Object.prototype.toString.call(t)}:Array.isArray,b=!s||!o.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView?ArrayBuffer.isView:function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer},_=function(t){var r=typeof t;if("string"===r)return[t,!0];if("object"!==r||null===t)throw new Error(e);if(s&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!k(t)&&!b(t))throw new Error(e);return[t,!1]},v=function(t){return 0===_(t)[0].length},g=function(t){for(var e=[],r=0;r<t.length;++r)e[r]=t[r];return e},A=function(t,e,r){return function(n){return new I(t,e,t).update(n)[r]()}},w=function(t,e,r){return function(n,o){return new I(t,e,o).update(n)[r]()}},B=function(t,e,r){return function(e,n,o,i){return O["cshake"+t].update(e,n,o,i)[r]()}},S=function(t,e,r){return function(e,n,o,i){return O["kmac"+t].update(e,n,o,i)[r]()}},x=function(t,e,r,n){for(var o=0;o<l.length;++o){var i=l[o];t[i]=e(r,n,i)}return t},C=function(t,e){var r=A(t,e,"hex");return r.create=function(){return new I(t,e,t)},r.update=function(t){return r.create().update(t)},x(r,A,t,e)},m=[{name:"keccak",padding:[1,256,65536,16777216],bits:p,createMethod:C},{name:"sha3",padding:[6,1536,393216,100663296],bits:p,createMethod:C},{name:"shake",padding:[31,7936,2031616,520093696],bits:d,createMethod:function(t,e){var r=w(t,e,"hex");return r.create=function(r){return new I(t,e,r)},r.update=function(t,e){return r.create(e).update(t)},x(r,w,t,e)}},{name:"cshake",padding:f,bits:d,createMethod:function(t,e){var r=y[t],n=B(t,0,"hex");return n.create=function(n,o,i){return v(o)&&v(i)?O["shake"+t].create(n):new I(t,e,n).bytepad([o,i],r)},n.update=function(t,e,r,o){return n.create(e,r,o).update(t)},x(n,B,t,e)}},{name:"kmac",padding:f,bits:d,createMethod:function(t,e){var r=y[t],n=S(t,0,"hex");return n.create=function(n,o,i){return new R(t,e,o).bytepad(["KMAC",i],r).bytepad([n],r)},n.update=function(t,e,r,o){return n.create(t,r,o).update(e)},x(n,S,t,e)}}],O={},z=[],M=0;M<m.length;++M)for(var N=m[M],J=N.bits,j=0;j<J.length;++j){var E=N.name+"_"+J[j];if(z.push(E),O[E]=N.createMethod(J[j],N.padding),"sha3"!==N.name){var H=N.name+J[j];z.push(H),O[H]=O[E]}}function I(t,e,r){this.blocks=[],this.s=[],this.padding=e,this.outputBits=r,this.reset=!0,this.finalized=!1,this.block=0,this.start=0,this.blockCount=1600-(t<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=r>>5,this.extraBytes=(31&r)>>3;for(var n=0;n<50;++n)this.s[n]=0}function R(t,e,r){I.call(this,t,e,r)}I.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var e=_(t);t=e[0];for(var r,n,o=e[1],i=this.blocks,a=this.byteCount,s=t.length,u=this.blockCount,f=0,h=this.s;f<s;){if(this.reset)for(this.reset=!1,i[0]=this.block,r=1;r<u+1;++r)i[r]=0;if(o)for(r=this.start;f<s&&r<a;++f)(n=t.charCodeAt(f))<128?i[r>>2]|=n<<c[3&r++]:n<2048?(i[r>>2]|=(192|n>>6)<<c[3&r++],i[r>>2]|=(128|63&n)<<c[3&r++]):n<55296||n>=57344?(i[r>>2]|=(224|n>>12)<<c[3&r++],i[r>>2]|=(128|n>>6&63)<<c[3&r++],i[r>>2]|=(128|63&n)<<c[3&r++]):(n=65536+((1023&n)<<10|1023&t.charCodeAt(++f)),i[r>>2]|=(240|n>>18)<<c[3&r++],i[r>>2]|=(128|n>>12&63)<<c[3&r++],i[r>>2]|=(128|n>>6&63)<<c[3&r++],i[r>>2]|=(128|63&n)<<c[3&r++]);else for(r=this.start;f<s&&r<a;++f)i[r>>2]|=t[f]<<c[3&r++];if(this.lastByteIndex=r,r>=a){for(this.start=r-a,this.block=i[u],r=0;r<u;++r)h[r]^=i[r];F(h),this.reset=!0}else this.start=r}return this},I.prototype.encode=function(t,e){var r=255&t,n=1,o=[r];for(r=255&(t>>=8);r>0;)o.unshift(r),r=255&(t>>=8),++n;return e?o.push(n):o.unshift(n),this.update(o),o.length},I.prototype.encodeString=function(t){var e=_(t);t=e[0];var r=e[1],n=0,o=t.length;if(r)for(var i=0;i<t.length;++i){var a=t.charCodeAt(i);a<128?n+=1:a<2048?n+=2:a<55296||a>=57344?n+=3:(a=65536+((1023&a)<<10|1023&t.charCodeAt(++i)),n+=4)}else n=o;return n+=this.encode(8*n),this.update(t),n},I.prototype.bytepad=function(t,e){for(var r=this.encode(e),n=0;n<t.length;++n)r+=this.encodeString(t[n]);var o=(e-r%e)%e,i=[];return i.length=o,this.update(i),this},I.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,e=this.lastByteIndex,r=this.blockCount,n=this.s;if(t[e>>2]|=this.padding[3&e],this.lastByteIndex===this.byteCount)for(t[0]=t[r],e=1;e<r+1;++e)t[e]=0;for(t[r-1]|=2147483648,e=0;e<r;++e)n[e]^=t[e];F(n)}},I.prototype.toString=I.prototype.hex=function(){this.finalize();for(var t,e=this.blockCount,r=this.s,n=this.outputBlocks,o=this.extraBytes,i=0,a=0,s="";a<n;){for(i=0;i<e&&a<n;++i,++a)t=r[i],s+=u[t>>4&15]+u[15&t]+u[t>>12&15]+u[t>>8&15]+u[t>>20&15]+u[t>>16&15]+u[t>>28&15]+u[t>>24&15];a%e===0&&(r=g(r),F(r),i=0)}return o&&(t=r[i],s+=u[t>>4&15]+u[15&t],o>1&&(s+=u[t>>12&15]+u[t>>8&15]),o>2&&(s+=u[t>>20&15]+u[t>>16&15])),s},I.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,r=this.s,n=this.outputBlocks,o=this.extraBytes,i=0,a=0,s=this.outputBits>>3;t=o?new ArrayBuffer(n+1<<2):new ArrayBuffer(s);for(var u=new Uint32Array(t);a<n;){for(i=0;i<e&&a<n;++i,++a)u[a]=r[i];a%e===0&&(r=g(r),F(r))}return o&&(u[a]=r[i],t=t.slice(0,s)),t},I.prototype.buffer=I.prototype.arrayBuffer,I.prototype.digest=I.prototype.array=function(){this.finalize();for(var t,e,r=this.blockCount,n=this.s,o=this.outputBlocks,i=this.extraBytes,a=0,s=0,u=[];s<o;){for(a=0;a<r&&s<o;++a,++s)t=s<<2,e=n[a],u[t]=255&e,u[t+1]=e>>8&255,u[t+2]=e>>16&255,u[t+3]=e>>24&255;s%r===0&&(n=g(n),F(n))}return i&&(t=s<<2,e=n[a],u[t]=255&e,i>1&&(u[t+1]=e>>8&255),i>2&&(u[t+2]=e>>16&255)),u},R.prototype=new I,R.prototype.finalize=function(){return this.encode(this.outputBits,!0),I.prototype.finalize.call(this)};var F=function(t){var e,r,n,o,i,a,s,u,f,c,p,d,l,y,k,b,_,v,g,A,w,B,S,x,C,m,O,z,M,N,J,j,E,H,I,R,F,U,D,V,W,T,Y,K,P,q,G,L,Q,X,Z,$,tt,et,rt,nt,ot,it,at,st,ut,ft,ct;for(n=0;n<48;n+=2)o=t[0]^t[10]^t[20]^t[30]^t[40],i=t[1]^t[11]^t[21]^t[31]^t[41],a=t[2]^t[12]^t[22]^t[32]^t[42],s=t[3]^t[13]^t[23]^t[33]^t[43],u=t[4]^t[14]^t[24]^t[34]^t[44],f=t[5]^t[15]^t[25]^t[35]^t[45],c=t[6]^t[16]^t[26]^t[36]^t[46],p=t[7]^t[17]^t[27]^t[37]^t[47],e=(d=t[8]^t[18]^t[28]^t[38]^t[48])^(a<<1|s>>>31),r=(l=t[9]^t[19]^t[29]^t[39]^t[49])^(s<<1|a>>>31),t[0]^=e,t[1]^=r,t[10]^=e,t[11]^=r,t[20]^=e,t[21]^=r,t[30]^=e,t[31]^=r,t[40]^=e,t[41]^=r,e=o^(u<<1|f>>>31),r=i^(f<<1|u>>>31),t[2]^=e,t[3]^=r,t[12]^=e,t[13]^=r,t[22]^=e,t[23]^=r,t[32]^=e,t[33]^=r,t[42]^=e,t[43]^=r,e=a^(c<<1|p>>>31),r=s^(p<<1|c>>>31),t[4]^=e,t[5]^=r,t[14]^=e,t[15]^=r,t[24]^=e,t[25]^=r,t[34]^=e,t[35]^=r,t[44]^=e,t[45]^=r,e=u^(d<<1|l>>>31),r=f^(l<<1|d>>>31),t[6]^=e,t[7]^=r,t[16]^=e,t[17]^=r,t[26]^=e,t[27]^=r,t[36]^=e,t[37]^=r,t[46]^=e,t[47]^=r,e=c^(o<<1|i>>>31),r=p^(i<<1|o>>>31),t[8]^=e,t[9]^=r,t[18]^=e,t[19]^=r,t[28]^=e,t[29]^=r,t[38]^=e,t[39]^=r,t[48]^=e,t[49]^=r,y=t[0],k=t[1],q=t[11]<<4|t[10]>>>28,G=t[10]<<4|t[11]>>>28,z=t[20]<<3|t[21]>>>29,M=t[21]<<3|t[20]>>>29,st=t[31]<<9|t[30]>>>23,ut=t[30]<<9|t[31]>>>23,T=t[40]<<18|t[41]>>>14,Y=t[41]<<18|t[40]>>>14,H=t[2]<<1|t[3]>>>31,I=t[3]<<1|t[2]>>>31,b=t[13]<<12|t[12]>>>20,_=t[12]<<12|t[13]>>>20,L=t[22]<<10|t[23]>>>22,Q=t[23]<<10|t[22]>>>22,N=t[33]<<13|t[32]>>>19,J=t[32]<<13|t[33]>>>19,ft=t[42]<<2|t[43]>>>30,ct=t[43]<<2|t[42]>>>30,et=t[5]<<30|t[4]>>>2,rt=t[4]<<30|t[5]>>>2,R=t[14]<<6|t[15]>>>26,F=t[15]<<6|t[14]>>>26,v=t[25]<<11|t[24]>>>21,g=t[24]<<11|t[25]>>>21,X=t[34]<<15|t[35]>>>17,Z=t[35]<<15|t[34]>>>17,j=t[45]<<29|t[44]>>>3,E=t[44]<<29|t[45]>>>3,x=t[6]<<28|t[7]>>>4,C=t[7]<<28|t[6]>>>4,nt=t[17]<<23|t[16]>>>9,ot=t[16]<<23|t[17]>>>9,U=t[26]<<25|t[27]>>>7,D=t[27]<<25|t[26]>>>7,A=t[36]<<21|t[37]>>>11,w=t[37]<<21|t[36]>>>11,$=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,K=t[8]<<27|t[9]>>>5,P=t[9]<<27|t[8]>>>5,m=t[18]<<20|t[19]>>>12,O=t[19]<<20|t[18]>>>12,it=t[29]<<7|t[28]>>>25,at=t[28]<<7|t[29]>>>25,V=t[38]<<8|t[39]>>>24,W=t[39]<<8|t[38]>>>24,B=t[48]<<14|t[49]>>>18,S=t[49]<<14|t[48]>>>18,t[0]=y^~b&v,t[1]=k^~_&g,t[10]=x^~m&z,t[11]=C^~O&M,t[20]=H^~R&U,t[21]=I^~F&D,t[30]=K^~q&L,t[31]=P^~G&Q,t[40]=et^~nt&it,t[41]=rt^~ot&at,t[2]=b^~v&A,t[3]=_^~g&w,t[12]=m^~z&N,t[13]=O^~M&J,t[22]=R^~U&V,t[23]=F^~D&W,t[32]=q^~L&X,t[33]=G^~Q&Z,t[42]=nt^~it&st,t[43]=ot^~at&ut,t[4]=v^~A&B,t[5]=g^~w&S,t[14]=z^~N&j,t[15]=M^~J&E,t[24]=U^~V&T,t[25]=D^~W&Y,t[34]=L^~X&$,t[35]=Q^~Z&tt,t[44]=it^~st&ft,t[45]=at^~ut&ct,t[6]=A^~B&y,t[7]=w^~S&k,t[16]=N^~j&x,t[17]=J^~E&C,t[26]=V^~T&H,t[27]=W^~Y&I,t[36]=X^~$&K,t[37]=Z^~tt&P,t[46]=st^~ft&et,t[47]=ut^~ct&rt,t[8]=B^~y&b,t[9]=S^~k&_,t[18]=j^~x&m,t[19]=E^~C&O,t[28]=T^~H&R,t[29]=Y^~I&F,t[38]=$^~K&q,t[39]=tt^~P&G,t[48]=ft^~et&nt,t[49]=ct^~rt&ot,t[0]^=h[n],t[1]^=h[n+1]};if(a)r.exports=O;else for(M=0;M<z.length;++M)o[z[M]]=O[z[M]]}();var o=e(n.exports);const{sha3_224:i,sha3_256:a,sha3_384:s,sha3_512:u,keccak_224:f,keccak_256:c,keccak_384:h,keccak_512:p,keccak224:d,keccak256:l,keccak384:y,keccak512:k,shake_128:b,shake_256:_,shake128:v,shake256:g,cshake_128:A,cshake_256:w,cshake128:B,cshake256:S,kmac_128:x,kmac_256:C,kmac128:m,kmac256:O}=o;export{B as cshake128,S as cshake256,A as cshake_128,w as cshake_256,o as default,d as keccak224,l as keccak256,y as keccak384,k as keccak512,f as keccak_224,c as keccak_256,h as keccak_384,p as keccak_512,m as kmac128,O as kmac256,x as kmac_128,C as kmac_256,i as sha3_224,a as sha3_256,s as sha3_384,u as sha3_512,v as shake128,g as shake256,b as shake_128,_ as shake_256};
|
|
9
|
+
*/r=n,function(){var e="input is invalid type",n="tuple input is incomplete",i="object"==typeof window,o=i?window:{};o.JS_SHA3_NO_WINDOW&&(i=!1);var a=!i&&"object"==typeof self;!o.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?o=t:a&&(o=self);for(var u=!o.JS_SHA3_NO_COMMON_JS&&r.exports,s=!o.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,h="0123456789abcdef".split(""),f=[4,1024,262144,67108864],c=[0,8,16,24],p=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],l=[224,256,384,512],d=[128,256],y=["hex","buffer","arrayBuffer","array","digest"],k={128:168,256:136},g=o.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return"[object Array]"===Object.prototype.toString.call(t)}:Array.isArray,v=!s||!o.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView?ArrayBuffer.isView:function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer},b=function(t){var r=typeof t;if("string"===r)return[t,!0];if("object"!==r||null===t)throw new Error(e);if(s&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!g(t)&&!v(t))throw new Error(e);return[t,!1]},_=function(t){return 0===b(t)[0].length},w=function(t){for(var e=[],r=0;r<t.length;++r)e[r]=t[r];return e},A=function(t,e,r){return function(n){return new D(t,e,t).update(n)[r]()}},x=function(t,e,r){return function(n,i){return new D(t,e,i).update(n)[r]()}},B=function(t,e,r){return function(e,n,i,o){return R["cshake"+t].update(e,n,i,o)[r]()}},m=function(t,e,r,n){return function(e,i,o,a){return R[(r?"kmacxof":"kmac")+t].update(e,i,o,a)[n]()}},C=function(t,e,r,n){return function(e,i,o){return R[(r?"tuplehashxof":"tuplehash")+t].update(e,i,o)[n]()}},S=function(t,e,r,n){for(var i=0;i<y.length;++i){var o=y[i];t[o]=e(r,n,o)}return t},M=function(t,e){var r=A(t,e,"hex");return r.create=function(){return new D(t,e,t)},r.update=function(t){return r.create().update(t)},S(r,A,t,e)},z=function(t,e,r){var n=k[t],i=m(t,0,r,"hex");return i.create=function(i,o,a){return new L(t,e,o,r).bytepad(["KMAC",a],n).bytepad([i],n)},i.update=function(t,e,r,n){return i.create(t,r,n).update(e)},S(i,function(t,e,n){return m(t,0,r,n)},t,e)},E=function(t,r,n){var i=k[t],o=C(t,0,n,"hex");return o.create=function(e,o){return new T(t,r,e,n).bytepad(["TupleHash",o],i)},o.update=function(t,r,n){if(!g(t))throw new Error(e);for(var i=o.create(r,n),a=0;a<t.length;++a)i.update(t[a]);return i},S(o,function(t,e,r){return C(t,0,n,r)},t,r)},O=[{name:"keccak",padding:[1,256,65536,16777216],bits:l,createMethod:M},{name:"sha3",padding:[6,1536,393216,100663296],bits:l,createMethod:M},{name:"shake",padding:[31,7936,2031616,520093696],bits:d,createMethod:function(t,e){var r=x(t,e,"hex");return r.create=function(r){return new D(t,e,r)},r.update=function(t,e){return r.create(e).update(t)},S(r,x,t,e)}},{name:"cshake",padding:f,bits:d,createMethod:function(t,e){var r=k[t],n=B(t,0,"hex");return n.create=function(n,i,o){return _(i)&&_(o)?R["shake"+t].create(n):new D(t,e,n).bytepad([i,o],r)},n.update=function(t,e,r,i){return n.create(e,r,i).update(t)},S(n,B,t,e)}},{name:"kmac",padding:f,bits:d,createMethod:function(t,e){return z(t,e,!1)}},{name:"kmacxof",padding:f,bits:d,createMethod:function(t,e){return z(t,e,!0)}},{name:"tuplehash",padding:f,bits:d,createMethod:function(t,e){return E(t,e,!1)}},{name:"tuplehashxof",padding:f,bits:d,createMethod:function(t,e){return E(t,e,!0)}}],R={},N=[],J=0;J<O.length;++J)for(var j=O[J],I=j.bits,H=0;H<I.length;++H){var F=j.name+"_"+I[H];if(N.push(F),R[F]=j.createMethod(I[H],j.padding),"sha3"!==j.name){var U=j.name+I[H];N.push(U),R[U]=R[F]}}function D(t,e,r){this.blocks=[],this.s=[],this.padding=e,this.outputBits=r,this.reset=!0,this.finalized=!1,this.block=0,this.start=0,this.blockCount=1600-(t<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=r>>5,this.extraBytes=(31&r)>>3;for(var n=0;n<50;++n)this.s[n]=0}function L(t,e,r,n){D.call(this,t,e,r),this.xof=n}function T(t,e,r,n){L.call(this,t,e,r,n),this.inputActive=!1,this.inputBytesRemaining=0}D.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var e=b(t);t=e[0];for(var r,n,i=e[1],o=this.blocks,a=this.byteCount,u=t.length,s=this.blockCount,h=0,f=this.s;h<u;){if(this.reset)for(this.reset=!1,o[0]=this.block,r=1;r<s+1;++r)o[r]=0;if(i)for(r=this.start;h<u&&r<a;++h)(n=t.charCodeAt(h))<128?o[r>>2]|=n<<c[3&r++]:n<2048?(o[r>>2]|=(192|n>>6)<<c[3&r++],o[r>>2]|=(128|63&n)<<c[3&r++]):n<55296||n>=57344?(o[r>>2]|=(224|n>>12)<<c[3&r++],o[r>>2]|=(128|n>>6&63)<<c[3&r++],o[r>>2]|=(128|63&n)<<c[3&r++]):(n=65536+((1023&n)<<10|1023&t.charCodeAt(++h)),o[r>>2]|=(240|n>>18)<<c[3&r++],o[r>>2]|=(128|n>>12&63)<<c[3&r++],o[r>>2]|=(128|n>>6&63)<<c[3&r++],o[r>>2]|=(128|63&n)<<c[3&r++]);else for(r=this.start;h<u&&r<a;++h)o[r>>2]|=t[h]<<c[3&r++];if(this.lastByteIndex=r,r>=a){for(this.start=r-a,this.block=o[s],r=0;r<s;++r)f[r]^=o[r];V(f),this.reset=!0}else this.start=r}return this},D.prototype.encode=function(t,e){var r=255&t,n=1,i=[r];for(r=255&(t>>=8);r>0;)i.unshift(r),r=255&(t>>=8),++n;return e?i.push(n):i.unshift(n),D.prototype.update.call(this,i),i.length},D.prototype.encodeString=function(t){var e=b(t);t=e[0];var r=e[1],n=0,i=t.length;if(r)for(var o=0;o<t.length;++o){var a=t.charCodeAt(o);a<128?n+=1:a<2048?n+=2:a<55296||a>=57344?n+=3:(a=65536+((1023&a)<<10|1023&t.charCodeAt(++o)),n+=4)}else n=i;return n+=this.encode(8*n),D.prototype.update.call(this,t),n},D.prototype.bytepad=function(t,e){for(var r=this.encode(e),n=0;n<t.length;++n)r+=this.encodeString(t[n]);var i=(e-r%e)%e,o=[];return o.length=i,D.prototype.update.call(this,o),this},D.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,e=this.lastByteIndex,r=this.blockCount,n=this.s;if(t[e>>2]|=this.padding[3&e],this.lastByteIndex===this.byteCount)for(t[0]=t[r],e=1;e<r+1;++e)t[e]=0;for(t[r-1]|=2147483648,e=0;e<r;++e)n[e]^=t[e];V(n)}},D.prototype.toString=D.prototype.hex=function(){this.finalize();for(var t,e=this.blockCount,r=this.s,n=this.outputBlocks,i=this.extraBytes,o=0,a=0,u="";a<n;){for(o=0;o<e&&a<n;++o,++a)t=r[o],u+=h[t>>4&15]+h[15&t]+h[t>>12&15]+h[t>>8&15]+h[t>>20&15]+h[t>>16&15]+h[t>>28&15]+h[t>>24&15];a%e===0&&(r=w(r),V(r),o=0)}return i&&(t=r[o],u+=h[t>>4&15]+h[15&t],i>1&&(u+=h[t>>12&15]+h[t>>8&15]),i>2&&(u+=h[t>>20&15]+h[t>>16&15])),u},D.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,r=this.s,n=this.outputBlocks,i=this.extraBytes,o=0,a=0,u=this.outputBits>>3;t=i?new ArrayBuffer(n+1<<2):new ArrayBuffer(u);for(var s=new Uint32Array(t);a<n;){for(o=0;o<e&&a<n;++o,++a)s[a]=r[o];a%e===0&&(r=w(r),V(r))}return i&&(s[a]=r[o],t=t.slice(0,u)),t},D.prototype.buffer=D.prototype.arrayBuffer,D.prototype.digest=D.prototype.array=function(){this.finalize();for(var t,e,r=this.blockCount,n=this.s,i=this.outputBlocks,o=this.extraBytes,a=0,u=0,s=[];u<i;){for(a=0;a<r&&u<i;++a,++u)t=u<<2,e=n[a],s[t]=255&e,s[t+1]=e>>8&255,s[t+2]=e>>16&255,s[t+3]=e>>24&255;u%r===0&&(n=w(n),V(n))}return o&&(t=u<<2,e=n[a],s[t]=255&e,o>1&&(s[t+1]=e>>8&255),o>2&&(s[t+2]=e>>16&255)),s},L.prototype=new D,L.prototype.finalize=function(){return this.finalized||this.encode(this.xof?0:this.outputBits,!0),D.prototype.finalize.call(this)},T.prototype=new L,T.prototype.getMessageByteLength=function(t){var e=b(t);if(t=e[0],!e[1])return t.length;for(var r=0,n=0;n<t.length;++n){var i=t.charCodeAt(n);i<128?r+=1:i<2048?r+=2:i<55296||i>=57344?r+=3:(++n,r+=4)}return r},T.prototype.beginInput=function(t){if(this.inputActive)throw new Error(n);if("number"!=typeof t||!isFinite(t)||t<0||Math.floor(t)!==t||t>268435455)throw new Error("tuple input byte length is invalid");return this.encode(8*t,!1),0!==t&&(this.inputActive=!0,this.inputBytesRemaining=t),this},T.prototype._updateChunk=function(t,e){return L.prototype.update.call(this,t),this.inputBytesRemaining-=e,0===this.inputBytesRemaining&&(this.inputActive=!1),this},T.prototype.updateChunk=function(t){if(!this.inputActive)throw new Error("no active tuple input");var e=this.getMessageByteLength(t);if(e>this.inputBytesRemaining)throw new Error("tuple input exceeds declared length");return this._updateChunk(t,e)},T.prototype.update=function(t){var e=this.getMessageByteLength(t);return this.beginInput(e),this._updateChunk(t,e)},T.prototype.finalize=function(){if(this.inputActive)throw new Error(n);return L.prototype.finalize.call(this)};var V=function(t){var e,r,n,i,o,a,u,s,h,f,c,l,d,y,k,g,v,b,_,w,A,x,B,m,C,S,M,z,E,O,R,N,J,j,I,H,F,U,D,L,T,V,W,Y,K,P,q,G,Q,X,Z,$,tt,et,rt,nt,it,ot,at,ut,st,ht,ft;for(n=0;n<48;n+=2)i=t[0]^t[10]^t[20]^t[30]^t[40],o=t[1]^t[11]^t[21]^t[31]^t[41],a=t[2]^t[12]^t[22]^t[32]^t[42],u=t[3]^t[13]^t[23]^t[33]^t[43],s=t[4]^t[14]^t[24]^t[34]^t[44],h=t[5]^t[15]^t[25]^t[35]^t[45],f=t[6]^t[16]^t[26]^t[36]^t[46],c=t[7]^t[17]^t[27]^t[37]^t[47],e=(l=t[8]^t[18]^t[28]^t[38]^t[48])^(a<<1|u>>>31),r=(d=t[9]^t[19]^t[29]^t[39]^t[49])^(u<<1|a>>>31),t[0]^=e,t[1]^=r,t[10]^=e,t[11]^=r,t[20]^=e,t[21]^=r,t[30]^=e,t[31]^=r,t[40]^=e,t[41]^=r,e=i^(s<<1|h>>>31),r=o^(h<<1|s>>>31),t[2]^=e,t[3]^=r,t[12]^=e,t[13]^=r,t[22]^=e,t[23]^=r,t[32]^=e,t[33]^=r,t[42]^=e,t[43]^=r,e=a^(f<<1|c>>>31),r=u^(c<<1|f>>>31),t[4]^=e,t[5]^=r,t[14]^=e,t[15]^=r,t[24]^=e,t[25]^=r,t[34]^=e,t[35]^=r,t[44]^=e,t[45]^=r,e=s^(l<<1|d>>>31),r=h^(d<<1|l>>>31),t[6]^=e,t[7]^=r,t[16]^=e,t[17]^=r,t[26]^=e,t[27]^=r,t[36]^=e,t[37]^=r,t[46]^=e,t[47]^=r,e=f^(i<<1|o>>>31),r=c^(o<<1|i>>>31),t[8]^=e,t[9]^=r,t[18]^=e,t[19]^=r,t[28]^=e,t[29]^=r,t[38]^=e,t[39]^=r,t[48]^=e,t[49]^=r,y=t[0],k=t[1],P=t[11]<<4|t[10]>>>28,q=t[10]<<4|t[11]>>>28,z=t[20]<<3|t[21]>>>29,E=t[21]<<3|t[20]>>>29,ut=t[31]<<9|t[30]>>>23,st=t[30]<<9|t[31]>>>23,V=t[40]<<18|t[41]>>>14,W=t[41]<<18|t[40]>>>14,j=t[2]<<1|t[3]>>>31,I=t[3]<<1|t[2]>>>31,g=t[13]<<12|t[12]>>>20,v=t[12]<<12|t[13]>>>20,G=t[22]<<10|t[23]>>>22,Q=t[23]<<10|t[22]>>>22,O=t[33]<<13|t[32]>>>19,R=t[32]<<13|t[33]>>>19,ht=t[42]<<2|t[43]>>>30,ft=t[43]<<2|t[42]>>>30,et=t[5]<<30|t[4]>>>2,rt=t[4]<<30|t[5]>>>2,H=t[14]<<6|t[15]>>>26,F=t[15]<<6|t[14]>>>26,b=t[25]<<11|t[24]>>>21,_=t[24]<<11|t[25]>>>21,X=t[34]<<15|t[35]>>>17,Z=t[35]<<15|t[34]>>>17,N=t[45]<<29|t[44]>>>3,J=t[44]<<29|t[45]>>>3,m=t[6]<<28|t[7]>>>4,C=t[7]<<28|t[6]>>>4,nt=t[17]<<23|t[16]>>>9,it=t[16]<<23|t[17]>>>9,U=t[26]<<25|t[27]>>>7,D=t[27]<<25|t[26]>>>7,w=t[36]<<21|t[37]>>>11,A=t[37]<<21|t[36]>>>11,$=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,Y=t[8]<<27|t[9]>>>5,K=t[9]<<27|t[8]>>>5,S=t[18]<<20|t[19]>>>12,M=t[19]<<20|t[18]>>>12,ot=t[29]<<7|t[28]>>>25,at=t[28]<<7|t[29]>>>25,L=t[38]<<8|t[39]>>>24,T=t[39]<<8|t[38]>>>24,x=t[48]<<14|t[49]>>>18,B=t[49]<<14|t[48]>>>18,t[0]=y^~g&b,t[1]=k^~v&_,t[10]=m^~S&z,t[11]=C^~M&E,t[20]=j^~H&U,t[21]=I^~F&D,t[30]=Y^~P&G,t[31]=K^~q&Q,t[40]=et^~nt&ot,t[41]=rt^~it&at,t[2]=g^~b&w,t[3]=v^~_&A,t[12]=S^~z&O,t[13]=M^~E&R,t[22]=H^~U&L,t[23]=F^~D&T,t[32]=P^~G&X,t[33]=q^~Q&Z,t[42]=nt^~ot&ut,t[43]=it^~at&st,t[4]=b^~w&x,t[5]=_^~A&B,t[14]=z^~O&N,t[15]=E^~R&J,t[24]=U^~L&V,t[25]=D^~T&W,t[34]=G^~X&$,t[35]=Q^~Z&tt,t[44]=ot^~ut&ht,t[45]=at^~st&ft,t[6]=w^~x&y,t[7]=A^~B&k,t[16]=O^~N&m,t[17]=R^~J&C,t[26]=L^~V&j,t[27]=T^~W&I,t[36]=X^~$&Y,t[37]=Z^~tt&K,t[46]=ut^~ht&et,t[47]=st^~ft&rt,t[8]=x^~y&g,t[9]=B^~k&v,t[18]=N^~m&S,t[19]=J^~C&M,t[28]=V^~j&H,t[29]=W^~I&F,t[38]=$^~Y&P,t[39]=tt^~K&q,t[48]=ht^~et&nt,t[49]=ft^~rt&it,t[0]^=p[n],t[1]^=p[n+1]};if(u)r.exports=R;else for(J=0;J<N.length;++J)o[N[J]]=R[N[J]]}();var i=e(n.exports);const{sha3_224:o,sha3_256:a,sha3_384:u,sha3_512:s,keccak_224:h,keccak_256:f,keccak_384:c,keccak_512:p,keccak224:l,keccak256:d,keccak384:y,keccak512:k,shake_128:g,shake_256:v,shake128:b,shake256:_,cshake_128:w,cshake_256:A,cshake128:x,cshake256:B,kmac_128:m,kmac_256:C,kmac128:S,kmac256:M,kmacxof_128:z,kmacxof_256:E,kmacxof128:O,kmacxof256:R,tuplehash_128:N,tuplehash_256:J,tuplehash128:j,tuplehash256:I,tuplehashxof_128:H,tuplehashxof_256:F,tuplehashxof128:U,tuplehashxof256:D}=i;export{x as cshake128,B as cshake256,w as cshake_128,A as cshake_256,i as default,l as keccak224,d as keccak256,y as keccak384,k as keccak512,h as keccak_224,f as keccak_256,c as keccak_384,p as keccak_512,S as kmac128,M as kmac256,m as kmac_128,C as kmac_256,O as kmacxof128,R as kmacxof256,z as kmacxof_128,E as kmacxof_256,o as sha3_224,a as sha3_256,u as sha3_384,s as sha3_512,b as shake128,_ as shake256,g as shake_128,v as shake_256,j as tuplehash128,I as tuplehash256,N as tuplehash_128,J as tuplehash_256,U as tuplehashxof128,D as tuplehashxof256,H as tuplehashxof_128,F as tuplehashxof_256};
|
package/build/sha3.mjs
CHANGED
|
@@ -9,9 +9,9 @@ var sha3$1 = {exports: {}};
|
|
|
9
9
|
/**
|
|
10
10
|
* [js-sha3]{@link https://github.com/emn178/js-sha3}
|
|
11
11
|
*
|
|
12
|
-
* @version 0.
|
|
12
|
+
* @version 0.12.0
|
|
13
13
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
14
|
-
* @copyright Chen, Yi-Cyuan 2015-
|
|
14
|
+
* @copyright Chen, Yi-Cyuan 2015-2026
|
|
15
15
|
* @license MIT
|
|
16
16
|
*/
|
|
17
17
|
|
|
@@ -21,6 +21,10 @@ var sha3$1 = {exports: {}};
|
|
|
21
21
|
|
|
22
22
|
var INPUT_ERROR = 'input is invalid type';
|
|
23
23
|
var FINALIZE_ERROR = 'finalize already called';
|
|
24
|
+
var TUPLE_ACTIVE_ERROR = 'no active tuple input';
|
|
25
|
+
var TUPLE_INCOMPLETE_ERROR = 'tuple input is incomplete';
|
|
26
|
+
var TUPLE_LENGTH_ERROR = 'tuple input exceeds declared length';
|
|
27
|
+
var TUPLE_BYTE_LENGTH_ERROR = 'tuple input byte length is invalid';
|
|
24
28
|
var WINDOW = typeof window === 'object';
|
|
25
29
|
var root = WINDOW ? window : {};
|
|
26
30
|
if (root.JS_SHA3_NO_WINDOW) {
|
|
@@ -115,9 +119,15 @@ var sha3$1 = {exports: {}};
|
|
|
115
119
|
};
|
|
116
120
|
};
|
|
117
121
|
|
|
118
|
-
var createKmacOutputMethod = function (bits, padding, outputType) {
|
|
122
|
+
var createKmacOutputMethod = function (bits, padding, xof, outputType) {
|
|
119
123
|
return function (key, message, outputBits, s) {
|
|
120
|
-
return methods['kmac' + bits].update(key, message, outputBits, s)[outputType]();
|
|
124
|
+
return methods[(xof ? 'kmacxof' : 'kmac') + bits].update(key, message, outputBits, s)[outputType]();
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
var createTupleHashOutputMethod = function (bits, padding, xof, outputType) {
|
|
129
|
+
return function (inputs, outputBits, s) {
|
|
130
|
+
return methods[(xof ? 'tuplehashxof' : 'tuplehash') + bits].update(inputs, outputBits, s)[outputType]();
|
|
121
131
|
};
|
|
122
132
|
};
|
|
123
133
|
|
|
@@ -167,16 +177,39 @@ var sha3$1 = {exports: {}};
|
|
|
167
177
|
return createOutputMethods(method, createCshakeOutputMethod, bits, padding);
|
|
168
178
|
};
|
|
169
179
|
|
|
170
|
-
var createKmacMethod = function (bits, padding) {
|
|
180
|
+
var createKmacMethod = function (bits, padding, xof) {
|
|
171
181
|
var w = CSHAKE_BYTEPAD[bits];
|
|
172
|
-
var method = createKmacOutputMethod(bits, padding, 'hex');
|
|
182
|
+
var method = createKmacOutputMethod(bits, padding, xof, 'hex');
|
|
173
183
|
method.create = function (key, outputBits, s) {
|
|
174
|
-
return new Kmac(bits, padding, outputBits).bytepad(['KMAC', s], w).bytepad([key], w);
|
|
184
|
+
return new Kmac(bits, padding, outputBits, xof).bytepad(['KMAC', s], w).bytepad([key], w);
|
|
175
185
|
};
|
|
176
186
|
method.update = function (key, message, outputBits, s) {
|
|
177
187
|
return method.create(key, outputBits, s).update(message);
|
|
178
188
|
};
|
|
179
|
-
return createOutputMethods(method,
|
|
189
|
+
return createOutputMethods(method, function (b, p, outputType) {
|
|
190
|
+
return createKmacOutputMethod(b, p, xof, outputType);
|
|
191
|
+
}, bits, padding);
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
var createTupleHashMethod = function (bits, padding, xof) {
|
|
195
|
+
var w = CSHAKE_BYTEPAD[bits];
|
|
196
|
+
var method = createTupleHashOutputMethod(bits, padding, xof, 'hex');
|
|
197
|
+
method.create = function (outputBits, s) {
|
|
198
|
+
return new TupleHash(bits, padding, outputBits, xof).bytepad(['TupleHash', s], w);
|
|
199
|
+
};
|
|
200
|
+
method.update = function (inputs, outputBits, s) {
|
|
201
|
+
if (!isArray(inputs)) {
|
|
202
|
+
throw new Error(INPUT_ERROR);
|
|
203
|
+
}
|
|
204
|
+
var hash = method.create(outputBits, s);
|
|
205
|
+
for (var i = 0; i < inputs.length; ++i) {
|
|
206
|
+
hash.update(inputs[i]);
|
|
207
|
+
}
|
|
208
|
+
return hash;
|
|
209
|
+
};
|
|
210
|
+
return createOutputMethods(method, function (b, p, outputType) {
|
|
211
|
+
return createTupleHashOutputMethod(b, p, xof, outputType);
|
|
212
|
+
}, bits, padding);
|
|
180
213
|
};
|
|
181
214
|
|
|
182
215
|
var algorithms = [
|
|
@@ -184,7 +217,18 @@ var sha3$1 = {exports: {}};
|
|
|
184
217
|
{ name: 'sha3', padding: PADDING, bits: BITS, createMethod: createMethod },
|
|
185
218
|
{ name: 'shake', padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod },
|
|
186
219
|
{ name: 'cshake', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createCshakeMethod },
|
|
187
|
-
{ name: 'kmac', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod:
|
|
220
|
+
{ name: 'kmac', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: function (bits, padding) {
|
|
221
|
+
return createKmacMethod(bits, padding, false);
|
|
222
|
+
}},
|
|
223
|
+
{ name: 'kmacxof', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: function (bits, padding) {
|
|
224
|
+
return createKmacMethod(bits, padding, true);
|
|
225
|
+
}},
|
|
226
|
+
{ name: 'tuplehash', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: function (bits, padding) {
|
|
227
|
+
return createTupleHashMethod(bits, padding, false);
|
|
228
|
+
}},
|
|
229
|
+
{ name: 'tuplehashxof', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: function (bits, padding) {
|
|
230
|
+
return createTupleHashMethod(bits, padding, true);
|
|
231
|
+
}}
|
|
188
232
|
];
|
|
189
233
|
|
|
190
234
|
var methods = {}, methodNames = [];
|
|
@@ -298,7 +342,7 @@ var sha3$1 = {exports: {}};
|
|
|
298
342
|
} else {
|
|
299
343
|
bytes.unshift(n);
|
|
300
344
|
}
|
|
301
|
-
|
|
345
|
+
Keccak.prototype.update.call(this, bytes);
|
|
302
346
|
return bytes.length;
|
|
303
347
|
};
|
|
304
348
|
|
|
@@ -325,7 +369,7 @@ var sha3$1 = {exports: {}};
|
|
|
325
369
|
bytes = length;
|
|
326
370
|
}
|
|
327
371
|
bytes += this.encode(bytes * 8);
|
|
328
|
-
|
|
372
|
+
Keccak.prototype.update.call(this, str);
|
|
329
373
|
return bytes;
|
|
330
374
|
};
|
|
331
375
|
|
|
@@ -337,7 +381,7 @@ var sha3$1 = {exports: {}};
|
|
|
337
381
|
var paddingBytes = (w - bytes % w) % w;
|
|
338
382
|
var zeros = [];
|
|
339
383
|
zeros.length = paddingBytes;
|
|
340
|
-
|
|
384
|
+
Keccak.prototype.update.call(this, zeros);
|
|
341
385
|
return this;
|
|
342
386
|
};
|
|
343
387
|
|
|
@@ -459,17 +503,100 @@ var sha3$1 = {exports: {}};
|
|
|
459
503
|
return array;
|
|
460
504
|
};
|
|
461
505
|
|
|
462
|
-
function Kmac(bits, padding, outputBits) {
|
|
506
|
+
function Kmac(bits, padding, outputBits, xof) {
|
|
463
507
|
Keccak.call(this, bits, padding, outputBits);
|
|
508
|
+
this.xof = xof;
|
|
464
509
|
}
|
|
465
510
|
|
|
466
511
|
Kmac.prototype = new Keccak();
|
|
467
512
|
|
|
468
513
|
Kmac.prototype.finalize = function () {
|
|
469
|
-
|
|
514
|
+
if (!this.finalized) {
|
|
515
|
+
this.encode(this.xof ? 0 : this.outputBits, true);
|
|
516
|
+
}
|
|
470
517
|
return Keccak.prototype.finalize.call(this);
|
|
471
518
|
};
|
|
472
519
|
|
|
520
|
+
function TupleHash(bits, padding, outputBits, xof) {
|
|
521
|
+
Kmac.call(this, bits, padding, outputBits, xof);
|
|
522
|
+
this.inputActive = false;
|
|
523
|
+
this.inputBytesRemaining = 0;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
TupleHash.prototype = new Kmac();
|
|
527
|
+
|
|
528
|
+
TupleHash.prototype.getMessageByteLength = function (message) {
|
|
529
|
+
var result = formatMessage(message);
|
|
530
|
+
message = result[0];
|
|
531
|
+
if (!result[1]) {
|
|
532
|
+
return message.length;
|
|
533
|
+
}
|
|
534
|
+
var bytes = 0;
|
|
535
|
+
for (var i = 0; i < message.length; ++i) {
|
|
536
|
+
var code = message.charCodeAt(i);
|
|
537
|
+
if (code < 0x80) {
|
|
538
|
+
bytes += 1;
|
|
539
|
+
} else if (code < 0x800) {
|
|
540
|
+
bytes += 2;
|
|
541
|
+
} else if (code < 0xd800 || code >= 0xe000) {
|
|
542
|
+
bytes += 3;
|
|
543
|
+
} else {
|
|
544
|
+
++i;
|
|
545
|
+
bytes += 4;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
return bytes;
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
TupleHash.prototype.beginInput = function (byteLength) {
|
|
552
|
+
if (this.inputActive) {
|
|
553
|
+
throw new Error(TUPLE_INCOMPLETE_ERROR);
|
|
554
|
+
}
|
|
555
|
+
if (typeof byteLength !== 'number' || !isFinite(byteLength) || byteLength < 0 ||
|
|
556
|
+
Math.floor(byteLength) !== byteLength || byteLength > 0x0fffffff) {
|
|
557
|
+
throw new Error(TUPLE_BYTE_LENGTH_ERROR);
|
|
558
|
+
}
|
|
559
|
+
this.encode(byteLength * 8, false);
|
|
560
|
+
if (byteLength !== 0) {
|
|
561
|
+
this.inputActive = true;
|
|
562
|
+
this.inputBytesRemaining = byteLength;
|
|
563
|
+
}
|
|
564
|
+
return this;
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
TupleHash.prototype._updateChunk = function (message, byteLength) {
|
|
568
|
+
Kmac.prototype.update.call(this, message);
|
|
569
|
+
this.inputBytesRemaining -= byteLength;
|
|
570
|
+
if (this.inputBytesRemaining === 0) {
|
|
571
|
+
this.inputActive = false;
|
|
572
|
+
}
|
|
573
|
+
return this;
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
TupleHash.prototype.updateChunk = function (message) {
|
|
577
|
+
if (!this.inputActive) {
|
|
578
|
+
throw new Error(TUPLE_ACTIVE_ERROR);
|
|
579
|
+
}
|
|
580
|
+
var byteLength = this.getMessageByteLength(message);
|
|
581
|
+
if (byteLength > this.inputBytesRemaining) {
|
|
582
|
+
throw new Error(TUPLE_LENGTH_ERROR);
|
|
583
|
+
}
|
|
584
|
+
return this._updateChunk(message, byteLength);
|
|
585
|
+
};
|
|
586
|
+
|
|
587
|
+
TupleHash.prototype.update = function (message) {
|
|
588
|
+
var byteLength = this.getMessageByteLength(message);
|
|
589
|
+
this.beginInput(byteLength);
|
|
590
|
+
return this._updateChunk(message, byteLength);
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
TupleHash.prototype.finalize = function () {
|
|
594
|
+
if (this.inputActive) {
|
|
595
|
+
throw new Error(TUPLE_INCOMPLETE_ERROR);
|
|
596
|
+
}
|
|
597
|
+
return Kmac.prototype.finalize.call(this);
|
|
598
|
+
};
|
|
599
|
+
|
|
473
600
|
var f = function (s) {
|
|
474
601
|
var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9,
|
|
475
602
|
b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17,
|
|
@@ -696,7 +823,20 @@ const {
|
|
|
696
823
|
kmac_128,
|
|
697
824
|
kmac_256,
|
|
698
825
|
kmac128,
|
|
699
|
-
kmac256
|
|
826
|
+
kmac256,
|
|
827
|
+
kmacxof_128,
|
|
828
|
+
kmacxof_256,
|
|
829
|
+
kmacxof128,
|
|
830
|
+
kmacxof256,
|
|
831
|
+
|
|
832
|
+
tuplehash_128,
|
|
833
|
+
tuplehash_256,
|
|
834
|
+
tuplehash128,
|
|
835
|
+
tuplehash256,
|
|
836
|
+
tuplehashxof_128,
|
|
837
|
+
tuplehashxof_256,
|
|
838
|
+
tuplehashxof128,
|
|
839
|
+
tuplehashxof256
|
|
700
840
|
} = sha3;
|
|
701
841
|
|
|
702
|
-
export { cshake128, cshake256, cshake_128, cshake_256, sha3 as default, keccak224, keccak256, keccak384, keccak512, keccak_224, keccak_256, keccak_384, keccak_512, kmac128, kmac256, kmac_128, kmac_256, sha3_224, sha3_256, sha3_384, sha3_512, shake128, shake256, shake_128, shake_256 };
|
|
842
|
+
export { cshake128, cshake256, cshake_128, cshake_256, sha3 as default, keccak224, keccak256, keccak384, keccak512, keccak_224, keccak_256, keccak_384, keccak_512, kmac128, kmac256, kmac_128, kmac_256, kmacxof128, kmacxof256, kmacxof_128, kmacxof_256, sha3_224, sha3_256, sha3_384, sha3_512, shake128, shake256, shake_128, shake_256, tuplehash128, tuplehash256, tuplehash_128, tuplehash_256, tuplehashxof128, tuplehashxof256, tuplehashxof_128, tuplehashxof_256 };
|
package/index.d.ts
CHANGED
|
@@ -291,6 +291,96 @@ interface KmacHash {
|
|
|
291
291
|
update(key: Message, message: Message, outputBits: number, customization: Message): Hasher;
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
+
type TupleInput = Message[];
|
|
295
|
+
|
|
296
|
+
interface TupleHash extends Hasher {
|
|
297
|
+
/**
|
|
298
|
+
* Start a streaming tuple input with a known UTF-8/binary byte length.
|
|
299
|
+
*
|
|
300
|
+
* @param byteLength The byte length of the input that will follow through updateChunk().
|
|
301
|
+
*/
|
|
302
|
+
beginInput(byteLength: number): TupleHash;
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Absorb part of the active streaming tuple input.
|
|
306
|
+
*
|
|
307
|
+
* @param message The next message chunk.
|
|
308
|
+
*/
|
|
309
|
+
updateChunk(message: Message): TupleHash;
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Append one complete tuple input string.
|
|
313
|
+
* Equivalent to beginInput(byteLength) followed by updateChunk(message).
|
|
314
|
+
*
|
|
315
|
+
* @param message The input string to encode and absorb.
|
|
316
|
+
*/
|
|
317
|
+
update(message: Message): TupleHash;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
interface TupleHashMethod {
|
|
321
|
+
/**
|
|
322
|
+
* Hash a tuple and return hex string.
|
|
323
|
+
*
|
|
324
|
+
* @param inputs The tuple of input strings.
|
|
325
|
+
* @param outputBits The length of output.
|
|
326
|
+
* @param customization The customization string.
|
|
327
|
+
*/
|
|
328
|
+
(inputs: TupleInput, outputBits: number, customization: Message): string;
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Hash a tuple and return hex string.
|
|
332
|
+
*
|
|
333
|
+
* @param inputs The tuple of input strings.
|
|
334
|
+
* @param outputBits The length of output.
|
|
335
|
+
* @param customization The customization string.
|
|
336
|
+
*/
|
|
337
|
+
hex(inputs: TupleInput, outputBits: number, customization: Message): string;
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Hash a tuple and return ArrayBuffer.
|
|
341
|
+
*
|
|
342
|
+
* @param inputs The tuple of input strings.
|
|
343
|
+
* @param outputBits The length of output.
|
|
344
|
+
* @param customization The customization string.
|
|
345
|
+
*/
|
|
346
|
+
arrayBuffer(inputs: TupleInput, outputBits: number, customization: Message): ArrayBuffer;
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Hash a tuple and return integer array.
|
|
350
|
+
*
|
|
351
|
+
* @param inputs The tuple of input strings.
|
|
352
|
+
* @param outputBits The length of output.
|
|
353
|
+
* @param customization The customization string.
|
|
354
|
+
*/
|
|
355
|
+
digest(inputs: TupleInput, outputBits: number, customization: Message): number[];
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Hash a tuple and return integer array.
|
|
359
|
+
*
|
|
360
|
+
* @param inputs The tuple of input strings.
|
|
361
|
+
* @param outputBits The length of output.
|
|
362
|
+
* @param customization The customization string.
|
|
363
|
+
*/
|
|
364
|
+
array(inputs: TupleInput, outputBits: number, customization: Message): number[];
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Create a TupleHash object.
|
|
368
|
+
*
|
|
369
|
+
* @param outputBits The length of output.
|
|
370
|
+
* @param customization The customization string.
|
|
371
|
+
*/
|
|
372
|
+
create(outputBits: number, customization: Message): TupleHash;
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Create a TupleHash object and absorb the given tuple inputs.
|
|
376
|
+
*
|
|
377
|
+
* @param inputs The tuple of input strings.
|
|
378
|
+
* @param outputBits The length of output.
|
|
379
|
+
* @param customization The customization string.
|
|
380
|
+
*/
|
|
381
|
+
update(inputs: TupleInput, outputBits: number, customization: Message): TupleHash;
|
|
382
|
+
}
|
|
383
|
+
|
|
294
384
|
export var sha3_512: Hash;
|
|
295
385
|
export var sha3_384: Hash;
|
|
296
386
|
export var sha3_256: Hash;
|
|
@@ -315,3 +405,15 @@ export var kmac_128: KmacHash;
|
|
|
315
405
|
export var kmac_256: KmacHash;
|
|
316
406
|
export var kmac128: KmacHash;
|
|
317
407
|
export var kmac256: KmacHash;
|
|
408
|
+
export var kmacxof_128: KmacHash;
|
|
409
|
+
export var kmacxof_256: KmacHash;
|
|
410
|
+
export var kmacxof128: KmacHash;
|
|
411
|
+
export var kmacxof256: KmacHash;
|
|
412
|
+
export var tuplehash_128: TupleHashMethod;
|
|
413
|
+
export var tuplehash_256: TupleHashMethod;
|
|
414
|
+
export var tuplehash128: TupleHashMethod;
|
|
415
|
+
export var tuplehash256: TupleHashMethod;
|
|
416
|
+
export var tuplehashxof_128: TupleHashMethod;
|
|
417
|
+
export var tuplehashxof_256: TupleHashMethod;
|
|
418
|
+
export var tuplehashxof128: TupleHashMethod;
|
|
419
|
+
export var tuplehashxof256: TupleHashMethod;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "js-sha3",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A simple SHA-3 / Keccak /
|
|
3
|
+
"version": "0.12.0",
|
|
4
|
+
"description": "A simple SHA-3 / Keccak / SHAKE / cSHAKE / KMAC / TupleHash hash function for JavaScript supports UTF-8 encoding.",
|
|
5
5
|
"main": "src/sha3.js",
|
|
6
6
|
"module": "build/sha3.mjs",
|
|
7
7
|
"exports": {
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"shake",
|
|
45
45
|
"cshake",
|
|
46
46
|
"kmac",
|
|
47
|
+
"tuplehash",
|
|
47
48
|
"hash",
|
|
48
49
|
"encryption",
|
|
49
50
|
"cryptography",
|
package/src/sha3.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* [js-sha3]{@link https://github.com/emn178/js-sha3}
|
|
3
3
|
*
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.12.0
|
|
5
5
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
6
|
-
* @copyright Chen, Yi-Cyuan 2015-
|
|
6
|
+
* @copyright Chen, Yi-Cyuan 2015-2026
|
|
7
7
|
* @license MIT
|
|
8
8
|
*/
|
|
9
9
|
/*jslint bitwise: true */
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
|
|
13
13
|
var INPUT_ERROR = 'input is invalid type';
|
|
14
14
|
var FINALIZE_ERROR = 'finalize already called';
|
|
15
|
+
var TUPLE_ACTIVE_ERROR = 'no active tuple input';
|
|
16
|
+
var TUPLE_INCOMPLETE_ERROR = 'tuple input is incomplete';
|
|
17
|
+
var TUPLE_LENGTH_ERROR = 'tuple input exceeds declared length';
|
|
18
|
+
var TUPLE_BYTE_LENGTH_ERROR = 'tuple input byte length is invalid';
|
|
15
19
|
var WINDOW = typeof window === 'object';
|
|
16
20
|
var root = WINDOW ? window : {};
|
|
17
21
|
if (root.JS_SHA3_NO_WINDOW) {
|
|
@@ -107,9 +111,15 @@
|
|
|
107
111
|
};
|
|
108
112
|
};
|
|
109
113
|
|
|
110
|
-
var createKmacOutputMethod = function (bits, padding, outputType) {
|
|
114
|
+
var createKmacOutputMethod = function (bits, padding, xof, outputType) {
|
|
111
115
|
return function (key, message, outputBits, s) {
|
|
112
|
-
return methods['kmac' + bits].update(key, message, outputBits, s)[outputType]();
|
|
116
|
+
return methods[(xof ? 'kmacxof' : 'kmac') + bits].update(key, message, outputBits, s)[outputType]();
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
var createTupleHashOutputMethod = function (bits, padding, xof, outputType) {
|
|
121
|
+
return function (inputs, outputBits, s) {
|
|
122
|
+
return methods[(xof ? 'tuplehashxof' : 'tuplehash') + bits].update(inputs, outputBits, s)[outputType]();
|
|
113
123
|
};
|
|
114
124
|
};
|
|
115
125
|
|
|
@@ -159,16 +169,39 @@
|
|
|
159
169
|
return createOutputMethods(method, createCshakeOutputMethod, bits, padding);
|
|
160
170
|
};
|
|
161
171
|
|
|
162
|
-
var createKmacMethod = function (bits, padding) {
|
|
172
|
+
var createKmacMethod = function (bits, padding, xof) {
|
|
163
173
|
var w = CSHAKE_BYTEPAD[bits];
|
|
164
|
-
var method = createKmacOutputMethod(bits, padding, 'hex');
|
|
174
|
+
var method = createKmacOutputMethod(bits, padding, xof, 'hex');
|
|
165
175
|
method.create = function (key, outputBits, s) {
|
|
166
|
-
return new Kmac(bits, padding, outputBits).bytepad(['KMAC', s], w).bytepad([key], w);
|
|
176
|
+
return new Kmac(bits, padding, outputBits, xof).bytepad(['KMAC', s], w).bytepad([key], w);
|
|
167
177
|
};
|
|
168
178
|
method.update = function (key, message, outputBits, s) {
|
|
169
179
|
return method.create(key, outputBits, s).update(message);
|
|
170
180
|
};
|
|
171
|
-
return createOutputMethods(method,
|
|
181
|
+
return createOutputMethods(method, function (b, p, outputType) {
|
|
182
|
+
return createKmacOutputMethod(b, p, xof, outputType);
|
|
183
|
+
}, bits, padding);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
var createTupleHashMethod = function (bits, padding, xof) {
|
|
187
|
+
var w = CSHAKE_BYTEPAD[bits];
|
|
188
|
+
var method = createTupleHashOutputMethod(bits, padding, xof, 'hex');
|
|
189
|
+
method.create = function (outputBits, s) {
|
|
190
|
+
return new TupleHash(bits, padding, outputBits, xof).bytepad(['TupleHash', s], w);
|
|
191
|
+
};
|
|
192
|
+
method.update = function (inputs, outputBits, s) {
|
|
193
|
+
if (!isArray(inputs)) {
|
|
194
|
+
throw new Error(INPUT_ERROR);
|
|
195
|
+
}
|
|
196
|
+
var hash = method.create(outputBits, s);
|
|
197
|
+
for (var i = 0; i < inputs.length; ++i) {
|
|
198
|
+
hash.update(inputs[i]);
|
|
199
|
+
}
|
|
200
|
+
return hash;
|
|
201
|
+
};
|
|
202
|
+
return createOutputMethods(method, function (b, p, outputType) {
|
|
203
|
+
return createTupleHashOutputMethod(b, p, xof, outputType);
|
|
204
|
+
}, bits, padding);
|
|
172
205
|
};
|
|
173
206
|
|
|
174
207
|
var algorithms = [
|
|
@@ -176,7 +209,18 @@
|
|
|
176
209
|
{ name: 'sha3', padding: PADDING, bits: BITS, createMethod: createMethod },
|
|
177
210
|
{ name: 'shake', padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod },
|
|
178
211
|
{ name: 'cshake', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createCshakeMethod },
|
|
179
|
-
{ name: 'kmac', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod:
|
|
212
|
+
{ name: 'kmac', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: function (bits, padding) {
|
|
213
|
+
return createKmacMethod(bits, padding, false);
|
|
214
|
+
}},
|
|
215
|
+
{ name: 'kmacxof', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: function (bits, padding) {
|
|
216
|
+
return createKmacMethod(bits, padding, true);
|
|
217
|
+
}},
|
|
218
|
+
{ name: 'tuplehash', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: function (bits, padding) {
|
|
219
|
+
return createTupleHashMethod(bits, padding, false);
|
|
220
|
+
}},
|
|
221
|
+
{ name: 'tuplehashxof', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: function (bits, padding) {
|
|
222
|
+
return createTupleHashMethod(bits, padding, true);
|
|
223
|
+
}}
|
|
180
224
|
];
|
|
181
225
|
|
|
182
226
|
var methods = {}, methodNames = [];
|
|
@@ -290,7 +334,7 @@
|
|
|
290
334
|
} else {
|
|
291
335
|
bytes.unshift(n);
|
|
292
336
|
}
|
|
293
|
-
|
|
337
|
+
Keccak.prototype.update.call(this, bytes);
|
|
294
338
|
return bytes.length;
|
|
295
339
|
};
|
|
296
340
|
|
|
@@ -317,7 +361,7 @@
|
|
|
317
361
|
bytes = length;
|
|
318
362
|
}
|
|
319
363
|
bytes += this.encode(bytes * 8);
|
|
320
|
-
|
|
364
|
+
Keccak.prototype.update.call(this, str);
|
|
321
365
|
return bytes;
|
|
322
366
|
};
|
|
323
367
|
|
|
@@ -329,7 +373,7 @@
|
|
|
329
373
|
var paddingBytes = (w - bytes % w) % w;
|
|
330
374
|
var zeros = [];
|
|
331
375
|
zeros.length = paddingBytes;
|
|
332
|
-
|
|
376
|
+
Keccak.prototype.update.call(this, zeros);
|
|
333
377
|
return this;
|
|
334
378
|
};
|
|
335
379
|
|
|
@@ -451,17 +495,100 @@
|
|
|
451
495
|
return array;
|
|
452
496
|
};
|
|
453
497
|
|
|
454
|
-
function Kmac(bits, padding, outputBits) {
|
|
498
|
+
function Kmac(bits, padding, outputBits, xof) {
|
|
455
499
|
Keccak.call(this, bits, padding, outputBits);
|
|
500
|
+
this.xof = xof;
|
|
456
501
|
}
|
|
457
502
|
|
|
458
503
|
Kmac.prototype = new Keccak();
|
|
459
504
|
|
|
460
505
|
Kmac.prototype.finalize = function () {
|
|
461
|
-
|
|
506
|
+
if (!this.finalized) {
|
|
507
|
+
this.encode(this.xof ? 0 : this.outputBits, true);
|
|
508
|
+
}
|
|
462
509
|
return Keccak.prototype.finalize.call(this);
|
|
463
510
|
};
|
|
464
511
|
|
|
512
|
+
function TupleHash(bits, padding, outputBits, xof) {
|
|
513
|
+
Kmac.call(this, bits, padding, outputBits, xof);
|
|
514
|
+
this.inputActive = false;
|
|
515
|
+
this.inputBytesRemaining = 0;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
TupleHash.prototype = new Kmac();
|
|
519
|
+
|
|
520
|
+
TupleHash.prototype.getMessageByteLength = function (message) {
|
|
521
|
+
var result = formatMessage(message);
|
|
522
|
+
message = result[0];
|
|
523
|
+
if (!result[1]) {
|
|
524
|
+
return message.length;
|
|
525
|
+
}
|
|
526
|
+
var bytes = 0;
|
|
527
|
+
for (var i = 0; i < message.length; ++i) {
|
|
528
|
+
var code = message.charCodeAt(i);
|
|
529
|
+
if (code < 0x80) {
|
|
530
|
+
bytes += 1;
|
|
531
|
+
} else if (code < 0x800) {
|
|
532
|
+
bytes += 2;
|
|
533
|
+
} else if (code < 0xd800 || code >= 0xe000) {
|
|
534
|
+
bytes += 3;
|
|
535
|
+
} else {
|
|
536
|
+
++i;
|
|
537
|
+
bytes += 4;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
return bytes;
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
TupleHash.prototype.beginInput = function (byteLength) {
|
|
544
|
+
if (this.inputActive) {
|
|
545
|
+
throw new Error(TUPLE_INCOMPLETE_ERROR);
|
|
546
|
+
}
|
|
547
|
+
if (typeof byteLength !== 'number' || !isFinite(byteLength) || byteLength < 0 ||
|
|
548
|
+
Math.floor(byteLength) !== byteLength || byteLength > 0x0fffffff) {
|
|
549
|
+
throw new Error(TUPLE_BYTE_LENGTH_ERROR);
|
|
550
|
+
}
|
|
551
|
+
this.encode(byteLength * 8, false);
|
|
552
|
+
if (byteLength !== 0) {
|
|
553
|
+
this.inputActive = true;
|
|
554
|
+
this.inputBytesRemaining = byteLength;
|
|
555
|
+
}
|
|
556
|
+
return this;
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
TupleHash.prototype._updateChunk = function (message, byteLength) {
|
|
560
|
+
Kmac.prototype.update.call(this, message);
|
|
561
|
+
this.inputBytesRemaining -= byteLength;
|
|
562
|
+
if (this.inputBytesRemaining === 0) {
|
|
563
|
+
this.inputActive = false;
|
|
564
|
+
}
|
|
565
|
+
return this;
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
TupleHash.prototype.updateChunk = function (message) {
|
|
569
|
+
if (!this.inputActive) {
|
|
570
|
+
throw new Error(TUPLE_ACTIVE_ERROR);
|
|
571
|
+
}
|
|
572
|
+
var byteLength = this.getMessageByteLength(message);
|
|
573
|
+
if (byteLength > this.inputBytesRemaining) {
|
|
574
|
+
throw new Error(TUPLE_LENGTH_ERROR);
|
|
575
|
+
}
|
|
576
|
+
return this._updateChunk(message, byteLength);
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
TupleHash.prototype.update = function (message) {
|
|
580
|
+
var byteLength = this.getMessageByteLength(message);
|
|
581
|
+
this.beginInput(byteLength);
|
|
582
|
+
return this._updateChunk(message, byteLength);
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
TupleHash.prototype.finalize = function () {
|
|
586
|
+
if (this.inputActive) {
|
|
587
|
+
throw new Error(TUPLE_INCOMPLETE_ERROR);
|
|
588
|
+
}
|
|
589
|
+
return Kmac.prototype.finalize.call(this);
|
|
590
|
+
};
|
|
591
|
+
|
|
465
592
|
var f = function (s) {
|
|
466
593
|
var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9,
|
|
467
594
|
b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17,
|
package/src/sha3.mjs
CHANGED
|
@@ -28,7 +28,20 @@ export const {
|
|
|
28
28
|
kmac_128,
|
|
29
29
|
kmac_256,
|
|
30
30
|
kmac128,
|
|
31
|
-
kmac256
|
|
31
|
+
kmac256,
|
|
32
|
+
kmacxof_128,
|
|
33
|
+
kmacxof_256,
|
|
34
|
+
kmacxof128,
|
|
35
|
+
kmacxof256,
|
|
36
|
+
|
|
37
|
+
tuplehash_128,
|
|
38
|
+
tuplehash_256,
|
|
39
|
+
tuplehash128,
|
|
40
|
+
tuplehash256,
|
|
41
|
+
tuplehashxof_128,
|
|
42
|
+
tuplehashxof_256,
|
|
43
|
+
tuplehashxof128,
|
|
44
|
+
tuplehashxof256
|
|
32
45
|
} = sha3;
|
|
33
46
|
|
|
34
47
|
export default sha3;
|