js-sha3 0.10.0 → 0.11.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 +7 -0
- package/README.md +38 -3
- package/build/sha3.min.js +2 -2
- package/build/sha3.min.mjs +2 -2
- package/build/sha3.mjs +154 -8
- package/index.d.ts +98 -0
- package/package.json +3 -2
- package/src/sha3.js +143 -6
- package/src/sha3.mjs +10 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## v0.11.0 / 2026-07-18
|
|
4
|
+
### Added
|
|
5
|
+
- TupleHash128, TupleHash256, TupleHashXOF128, and TupleHashXOF256 (NIST SP 800-185)
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
- KMAC repeated output reads after finalize
|
|
9
|
+
|
|
3
10
|
## v0.10.0 / 2026-07-17
|
|
4
11
|
### Added
|
|
5
12
|
- support ESM #42, #38
|
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,10 @@ 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
|
+
tuplehash128(['abc', 'd'], 256, 'customization');
|
|
57
|
+
tuplehash256(['abc', 'd'], 512, 'customization');
|
|
58
|
+
tuplehashxof128(['abc', 'd'], 256, 'customization');
|
|
59
|
+
tuplehashxof256(['abc', 'd'], 512, 'customization');
|
|
56
60
|
|
|
57
61
|
// Support ArrayBuffer output
|
|
58
62
|
var arrayBuffer = keccak224.arrayBuffer('Message to hash');
|
|
@@ -83,6 +87,29 @@ var hash = cshake128.create(256, 'function name', 'customization');
|
|
|
83
87
|
|
|
84
88
|
// specify kmac key, output bits and customization when creating
|
|
85
89
|
var hash = kmac128.create('key', 256, 'customization');
|
|
90
|
+
|
|
91
|
+
// TupleHash: a tuple contains zero or more input strings.
|
|
92
|
+
// One-shot and method-level update
|
|
93
|
+
tuplehash128(['abc', 'd'], 256, '');
|
|
94
|
+
tuplehash128.update(['abc', 'd'], 256, '').hex();
|
|
95
|
+
|
|
96
|
+
// Incremental complete inputs (each update is one tuple input string)
|
|
97
|
+
tuplehash128.create(256, '')
|
|
98
|
+
.update('abc')
|
|
99
|
+
.update('d')
|
|
100
|
+
.hex();
|
|
101
|
+
|
|
102
|
+
// Streaming a large input when its byte length is known in advance.
|
|
103
|
+
// beginInput + updateChunk; no endInput() is needed.
|
|
104
|
+
// Inputs are absorbed sequentially. TupleHash does not parallelize tuple inputs;
|
|
105
|
+
// use ParallelHash for parallel hashing of one large input.
|
|
106
|
+
var tupleHash = tuplehash128.create(256, '');
|
|
107
|
+
tupleHash.beginInput(3);
|
|
108
|
+
tupleHash.updateChunk([0x61, 0x62]);
|
|
109
|
+
tupleHash.updateChunk([0x63]);
|
|
110
|
+
tupleHash.beginInput(1);
|
|
111
|
+
tupleHash.updateChunk([0x64]);
|
|
112
|
+
tupleHash.hex();
|
|
86
113
|
```
|
|
87
114
|
### Node.js
|
|
88
115
|
If you use node.js, you should require the module first:
|
|
@@ -101,7 +128,11 @@ const {
|
|
|
101
128
|
cshake128,
|
|
102
129
|
cshake256,
|
|
103
130
|
kmac128,
|
|
104
|
-
kmac256
|
|
131
|
+
kmac256,
|
|
132
|
+
tuplehash128,
|
|
133
|
+
tuplehash256,
|
|
134
|
+
tuplehashxof128,
|
|
135
|
+
tuplehashxof256
|
|
105
136
|
} = require('js-sha3');
|
|
106
137
|
```
|
|
107
138
|
|
|
@@ -122,7 +153,11 @@ import {
|
|
|
122
153
|
cshake128,
|
|
123
154
|
cshake256,
|
|
124
155
|
kmac128,
|
|
125
|
-
kmac256
|
|
156
|
+
kmac256,
|
|
157
|
+
tuplehash128,
|
|
158
|
+
tuplehash256,
|
|
159
|
+
tuplehashxof128,
|
|
160
|
+
tuplehashxof256
|
|
126
161
|
} from 'js-sha3';
|
|
127
162
|
```
|
|
128
163
|
|
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.11.0
|
|
5
5
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
6
6
|
* @copyright Chen, Yi-Cyuan 2015-2023
|
|
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){t.call(this,e,r,n)}function r(e,r,n,i){t.call(this,e,r,n),this.xof=!!i,this.inputActive=!1,this.inputBytesRemaining=0}var n="input is invalid type",i="finalize already called",o="tuple input is incomplete",u="object"==typeof window,a=u?window:{};a.JS_SHA3_NO_WINDOW&&(u=!1);var s=!u&&"object"==typeof self;!a.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?a=global:s&&(a=self);for(var h=!a.JS_SHA3_NO_COMMON_JS&&"object"==typeof module&&module.exports,f="function"==typeof define&&define.amd,c=!a.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,p="0123456789abcdef".split(""),l=[4,1024,262144,67108864],d=[0,8,16,24],y=[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],g=[224,256,384,512],v=[128,256],b=["hex","buffer","arrayBuffer","array","digest"],w={128:168,256:136},A=a.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return"[object Array]"===Object.prototype.toString.call(t)}:Array.isArray,B=!c||!a.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView?ArrayBuffer.isView:function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer},k=function(t){var e=typeof t;if("string"===e)return[t,!0];if("object"!==e||null===t)throw new Error(n);if(c&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!A(t)&&!B(t))throw new Error(n);return[t,!1]},_=function(t){return 0===k(t)[0].length},m=function(t){for(var e=[],r=0;r<t.length;++r)e[r]=t[r];return e},x=function(e,r,n){return function(i){return new t(e,r,e).update(i)[n]()}},S=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]()}},z=function(t,e,r){return function(e,n,i,o){return J["kmac"+t].update(e,n,i,o)[r]()}},E=function(t,e,r,n){for(var i=0;i<b.length;++i){var o=b[i];t[o]=e(r,n,o)}return t},M=function(e,r){var n=x(e,r,"hex");return n.create=function(){return new t(e,r,e)},n.update=function(t){return n.create().update(t)},E(n,x,e,r)},O=function(t,e,r,n){return function(e,i,o){return J[(r?"tuplehashxof":"tuplehash")+t].update(e,i,o)[n]()}},R=function(t,e,i){var o=w[t],u=O(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(!A(t))throw new Error(n);for(var i=u.create(e,r),o=0;o<t.length;++o)i.update(t[o]);return i},E(u,function(t,e,r){return O(t,0,i,r)},t,e)},N=[{name:"keccak",padding:[1,256,65536,16777216],bits:g,createMethod:M},{name:"sha3",padding:[6,1536,393216,100663296],bits:g,createMethod:M},{name:"shake",padding:[31,7936,2031616,520093696],bits:v,createMethod:function(e,r){var n=S(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)},E(n,S,e,r)}},{name:"cshake",padding:l,bits:v,createMethod:function(e,r){var n=w[e],i=C(e,0,"hex");return i.create=function(i,o,u){return _(o)&&_(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)},E(i,C,e,r)}},{name:"kmac",padding:l,bits:v,createMethod:function(t,r){var n=w[t],i=z(t,0,"hex");return i.create=function(i,o,u){return new e(t,r,o).bytepad(["KMAC",u],n).bytepad([i],n)},i.update=function(t,e,r,n){return i.create(t,r,n).update(e)},E(i,z,t,r)}},{name:"tuplehash",padding:l,bits:v,createMethod:function(t,e){return R(t,e,!1)}},{name:"tuplehashxof",padding:l,bits:v,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(i);var e=k(t);t=e[0];for(var r,n,o=e[1],u=this.blocks,a=this.byteCount,s=t.length,h=this.blockCount,f=0,c=this.s;f<s;){if(this.reset)for(this.reset=!1,u[0]=this.block,r=1;r<h+1;++r)u[r]=0;if(o)for(r=this.start;f<s&&r<a;++f)(n=t.charCodeAt(f))<128?u[r>>2]|=n<<d[3&r++]:n<2048?(u[r>>2]|=(192|n>>6)<<d[3&r++],u[r>>2]|=(128|63&n)<<d[3&r++]):n<55296||n>=57344?(u[r>>2]|=(224|n>>12)<<d[3&r++],u[r>>2]|=(128|n>>6&63)<<d[3&r++],u[r>>2]|=(128|63&n)<<d[3&r++]):(n=65536+((1023&n)<<10|1023&t.charCodeAt(++f)),u[r>>2]|=(240|n>>18)<<d[3&r++],u[r>>2]|=(128|n>>12&63)<<d[3&r++],u[r>>2]|=(128|n>>6&63)<<d[3&r++],u[r>>2]|=(128|63&n)<<d[3&r++]);else for(r=this.start;f<s&&r<a;++f)u[r>>2]|=t[f]<<d[3&r++];if(this.lastByteIndex=r,r>=a){for(this.start=r-a,this.block=u[h],r=0;r<h;++r)c[r]^=u[r];V(c),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=k(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+=p[t>>4&15]+p[15&t]+p[t>>12&15]+p[t>>8&15]+p[t>>20&15]+p[t>>16&15]+p[t>>28&15]+p[t>>24&15];u%e==0&&(r=m(r),V(r),o=0)}return i&&(t=r[o],a+=p[t>>4&15]+p[15&t],i>1&&(a+=p[t>>12&15]+p[t>>8&15]),i>2&&(a+=p[t>>20&15]+p[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=m(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=m(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.outputBits,!0),t.prototype.finalize.call(this)},(r.prototype=new t).getMessageByteLength=function(t){var e=k(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.finalized)throw new Error(i);if(this.inputActive)throw new Error(o);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=!1,this.inputBytesRemaining=0):(this.inputActive=!0,this.inputBytesRemaining=t),this},r.prototype.updateChunk=function(e){if(this.finalized)throw new Error(i);if(!this.inputActive)throw new Error("no active tuple input");var r=this.getMessageByteLength(e);if(r>this.inputBytesRemaining)throw new Error("tuple input exceeds declared length");return t.prototype.update.call(this,e),this.inputBytesRemaining-=r,0===this.inputBytesRemaining&&(this.inputActive=!1),this},r.prototype.update=function(t){if(this.finalized)throw new Error(i);if(this.inputActive)throw new Error(o);var e=this.getMessageByteLength(t);return this.beginInput(e),0===e?this:this.updateChunk(t)},r.prototype.finalize=function(){if(this.inputActive)throw new Error(o);return this.finalized||this.encode(this.xof?0:this.outputBits,!0),t.prototype.finalize.call(this)};var V=function(t){var e,r,n,i,o,u,a,s,h,f,c,p,l,d,g,v,b,w,A,B,k,_,m,x,S,C,z,E,M,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,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],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],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=(p=t[8]^t[18]^t[28]^t[38]^t[48])^(u<<1|a>>>31),r=(l=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|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=u^(f<<1|c>>>31),r=a^(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^(p<<1|l>>>31),r=h^(l<<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=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,d=t[0],g=t[1],q=t[11]<<4|t[10]>>>28,G=t[10]<<4|t[11]>>>28,E=t[20]<<3|t[21]>>>29,M=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,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,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,S=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,C=t[18]<<20|t[19]>>>12,z=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]=d^~v&w,t[1]=g^~b&A,t[10]=x^~C&E,t[11]=S^~z&M,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]=C^~E&O,t[13]=z^~M&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]=E^~O&N,t[15]=M^~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&ht,t[45]=ut^~st&ft,t[6]=B^~_&d,t[7]=k^~m&g,t[16]=O^~N&x,t[17]=R^~J&S,t[26]=L^~W&j,t[27]=V^~Y&I,t[36]=X^~$&K,t[37]=Z^~tt&T,t[46]=at^~ht&et,t[47]=st^~ft&rt,t[8]=_^~d&v,t[9]=m^~g&b,t[18]=N^~x&C,t[19]=J^~S&z,t[28]=W^~j&H,t[29]=Y^~I&F,t[38]=$^~K&q,t[39]=tt^~T&G,t[48]=ht^~et&nt,t[49]=ft^~rt&it,t[0]^=y[n],t[1]^=y[n+1]};if(h)module.exports=J;else{for(I=0;I<j.length;++I)a[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.11.0
|
|
6
6
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
7
7
|
* @copyright Chen, Yi-Cyuan 2015-2023
|
|
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="finalize already called",i="tuple input is incomplete",o="object"==typeof window,a=o?window:{};a.JS_SHA3_NO_WINDOW&&(o=!1);var s=!o&&"object"==typeof self;!a.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?a=t:s&&(a=self);for(var u=!a.JS_SHA3_NO_COMMON_JS&&r.exports,h=!a.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,f="0123456789abcdef".split(""),c=[4,1024,262144,67108864],p=[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],d=[224,256,384,512],y=[128,256],g=["hex","buffer","arrayBuffer","array","digest"],k={128:168,256:136},v=a.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return"[object Array]"===Object.prototype.toString.call(t)}:Array.isArray,b=!h||!a.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView?ArrayBuffer.isView:function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer},w=function(t){var r=typeof t;if("string"===r)return[t,!0];if("object"!==r||null===t)throw new Error(e);if(h&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!v(t)&&!b(t))throw new Error(e);return[t,!1]},_=function(t){return 0===w(t)[0].length},A=function(t){for(var e=[],r=0;r<t.length;++r)e[r]=t[r];return e},B=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]()}},m=function(t,e,r){return function(e,n,i,o){return R["cshake"+t].update(e,n,i,o)[r]()}},S=function(t,e,r){return function(e,n,i,o){return R["kmac"+t].update(e,n,i,o)[r]()}},C=function(t,e,r,n){for(var i=0;i<g.length;++i){var o=g[i];t[o]=e(r,n,o)}return t},z=function(t,e){var r=B(t,e,"hex");return r.create=function(){return new D(t,e,t)},r.update=function(t){return r.create().update(t)},C(r,B,t,e)},E=function(t,e,r,n){return function(e,i,o){return R[(r?"tuplehashxof":"tuplehash")+t].update(e,i,o)[n]()}},M=function(t,r,n){var i=k[t],o=E(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(!v(t))throw new Error(e);for(var i=o.create(r,n),a=0;a<t.length;++a)i.update(t[a]);return i},C(o,function(t,e,r){return E(t,0,n,r)},t,r)},O=[{name:"keccak",padding:[1,256,65536,16777216],bits:d,createMethod:z},{name:"sha3",padding:[6,1536,393216,100663296],bits:d,createMethod:z},{name:"shake",padding:[31,7936,2031616,520093696],bits:y,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)},C(r,x,t,e)}},{name:"cshake",padding:c,bits:y,createMethod:function(t,e){var r=k[t],n=m(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)},C(n,m,t,e)}},{name:"kmac",padding:c,bits:y,createMethod:function(t,e){var r=k[t],n=S(t,0,"hex");return n.create=function(n,i,o){return new L(t,e,i).bytepad(["KMAC",o],r).bytepad([n],r)},n.update=function(t,e,r,i){return n.create(t,r,i).update(e)},C(n,S,t,e)}},{name:"tuplehash",padding:c,bits:y,createMethod:function(t,e){return M(t,e,!1)}},{name:"tuplehashxof",padding:c,bits:y,createMethod:function(t,e){return M(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){D.call(this,t,e,r)}function T(t,e,r,n){D.call(this,t,e,r),this.xof=!!n,this.inputActive=!1,this.inputBytesRemaining=0}D.prototype.update=function(t){if(this.finalized)throw new Error(n);var e=w(t);t=e[0];for(var r,i,o=e[1],a=this.blocks,s=this.byteCount,u=t.length,h=this.blockCount,f=0,c=this.s;f<u;){if(this.reset)for(this.reset=!1,a[0]=this.block,r=1;r<h+1;++r)a[r]=0;if(o)for(r=this.start;f<u&&r<s;++f)(i=t.charCodeAt(f))<128?a[r>>2]|=i<<p[3&r++]:i<2048?(a[r>>2]|=(192|i>>6)<<p[3&r++],a[r>>2]|=(128|63&i)<<p[3&r++]):i<55296||i>=57344?(a[r>>2]|=(224|i>>12)<<p[3&r++],a[r>>2]|=(128|i>>6&63)<<p[3&r++],a[r>>2]|=(128|63&i)<<p[3&r++]):(i=65536+((1023&i)<<10|1023&t.charCodeAt(++f)),a[r>>2]|=(240|i>>18)<<p[3&r++],a[r>>2]|=(128|i>>12&63)<<p[3&r++],a[r>>2]|=(128|i>>6&63)<<p[3&r++],a[r>>2]|=(128|63&i)<<p[3&r++]);else for(r=this.start;f<u&&r<s;++f)a[r>>2]|=t[f]<<p[3&r++];if(this.lastByteIndex=r,r>=s){for(this.start=r-s,this.block=a[h],r=0;r<h;++r)c[r]^=a[r];V(c),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=w(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,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=A(r),V(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},D.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=A(r),V(r))}return i&&(u[a]=r[o],t=t.slice(0,s)),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,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=A(n),V(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},L.prototype=new D,L.prototype.finalize=function(){return this.finalized||this.encode(this.outputBits,!0),D.prototype.finalize.call(this)},T.prototype=new D,T.prototype.getMessageByteLength=function(t){var e=w(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.finalized)throw new Error(n);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=!1,this.inputBytesRemaining=0):(this.inputActive=!0,this.inputBytesRemaining=t),this},T.prototype.updateChunk=function(t){if(this.finalized)throw new Error(n);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 D.prototype.update.call(this,t),this.inputBytesRemaining-=e,0===this.inputBytesRemaining&&(this.inputActive=!1),this},T.prototype.update=function(t){if(this.finalized)throw new Error(n);if(this.inputActive)throw new Error(i);var e=this.getMessageByteLength(t);return this.beginInput(e),0===e?this:this.updateChunk(t)},T.prototype.finalize=function(){if(this.inputActive)throw new Error(i);return this.finalized||this.encode(this.xof?0:this.outputBits,!0),D.prototype.finalize.call(this)};var V=function(t){var e,r,n,i,o,a,s,u,h,f,c,p,d,y,g,k,v,b,w,_,A,B,x,m,S,C,z,E,M,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,st,ut,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],s=t[3]^t[13]^t[23]^t[33]^t[43],u=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=(p=t[8]^t[18]^t[28]^t[38]^t[48])^(a<<1|s>>>31),r=(d=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|h>>>31),r=o^(h<<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^(f<<1|c>>>31),r=s^(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=u^(p<<1|d>>>31),r=h^(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=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],g=t[1],P=t[11]<<4|t[10]>>>28,q=t[10]<<4|t[11]>>>28,E=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,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,k=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,w=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,S=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,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,C=t[18]<<20|t[19]>>>12,z=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,B=t[48]<<14|t[49]>>>18,x=t[49]<<14|t[48]>>>18,t[0]=y^~k&b,t[1]=g^~v&w,t[10]=m^~C&E,t[11]=S^~z&M,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]=k^~b&_,t[3]=v^~w&A,t[12]=C^~E&O,t[13]=z^~M&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&st,t[43]=it^~at&ut,t[4]=b^~_&B,t[5]=w^~A&x,t[14]=E^~O&N,t[15]=M^~R&J,t[24]=U^~L&V,t[25]=D^~T&W,t[34]=G^~X&$,t[35]=Q^~Z&tt,t[44]=ot^~st&ht,t[45]=at^~ut&ft,t[6]=_^~B&y,t[7]=A^~x&g,t[16]=O^~N&m,t[17]=R^~J&S,t[26]=L^~V&j,t[27]=T^~W&I,t[36]=X^~$&Y,t[37]=Z^~tt&K,t[46]=st^~ht&et,t[47]=ut^~ft&rt,t[8]=B^~y&k,t[9]=x^~g&v,t[18]=N^~m&C,t[19]=J^~S&z,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]^=l[n],t[1]^=l[n+1]};if(u)r.exports=R;else for(J=0;J<N.length;++J)a[N[J]]=R[N[J]]}();var i=e(n.exports);const{sha3_224:o,sha3_256:a,sha3_384:s,sha3_512:u,keccak_224:h,keccak_256:f,keccak_384:c,keccak_512:p,keccak224:l,keccak256:d,keccak384:y,keccak512:g,shake_128:k,shake_256:v,shake128:b,shake256:w,cshake_128:_,cshake_256:A,cshake128:B,cshake256:x,kmac_128:m,kmac_256:S,kmac128:C,kmac256:z,tuplehash_128:E,tuplehash_256:M,tuplehash128:O,tuplehash256:R,tuplehashxof_128:N,tuplehashxof_256:J,tuplehashxof128:j,tuplehashxof256:I}=i;export{B as cshake128,x as cshake256,_ as cshake_128,A as cshake_256,i as default,l as keccak224,d as keccak256,y as keccak384,g as keccak512,h as keccak_224,f as keccak_256,c as keccak_384,p as keccak_512,C as kmac128,z as kmac256,m as kmac_128,S as kmac_256,o as sha3_224,a as sha3_256,s as sha3_384,u as sha3_512,b as shake128,w as shake256,k as shake_128,v as shake_256,O as tuplehash128,R as tuplehash256,E as tuplehash_128,M as tuplehash_256,j as tuplehashxof128,I as tuplehashxof256,N as tuplehashxof_128,J as tuplehashxof_256};
|
package/build/sha3.mjs
CHANGED
|
@@ -9,7 +9,7 @@ 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.11.0
|
|
13
13
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
14
14
|
* @copyright Chen, Yi-Cyuan 2015-2023
|
|
15
15
|
* @license MIT
|
|
@@ -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) {
|
|
@@ -179,12 +183,45 @@ var sha3$1 = {exports: {}};
|
|
|
179
183
|
return createOutputMethods(method, createKmacOutputMethod, bits, padding);
|
|
180
184
|
};
|
|
181
185
|
|
|
186
|
+
var createTupleHashOutputMethod = function (bits, padding, xof, outputType) {
|
|
187
|
+
return function (inputs, outputBits, s) {
|
|
188
|
+
return methods[(xof ? 'tuplehashxof' : 'tuplehash') + bits].update(inputs, outputBits, s)[outputType]();
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
var createTupleHashMethod = function (bits, padding, xof) {
|
|
193
|
+
var w = CSHAKE_BYTEPAD[bits];
|
|
194
|
+
var method = createTupleHashOutputMethod(bits, padding, xof, 'hex');
|
|
195
|
+
method.create = function (outputBits, s) {
|
|
196
|
+
return new TupleHash(bits, padding, outputBits, xof).bytepad(['TupleHash', s], w);
|
|
197
|
+
};
|
|
198
|
+
method.update = function (inputs, outputBits, s) {
|
|
199
|
+
if (!isArray(inputs)) {
|
|
200
|
+
throw new Error(INPUT_ERROR);
|
|
201
|
+
}
|
|
202
|
+
var hash = method.create(outputBits, s);
|
|
203
|
+
for (var i = 0; i < inputs.length; ++i) {
|
|
204
|
+
hash.update(inputs[i]);
|
|
205
|
+
}
|
|
206
|
+
return hash;
|
|
207
|
+
};
|
|
208
|
+
return createOutputMethods(method, function (b, p, outputType) {
|
|
209
|
+
return createTupleHashOutputMethod(b, p, xof, outputType);
|
|
210
|
+
}, bits, padding);
|
|
211
|
+
};
|
|
212
|
+
|
|
182
213
|
var algorithms = [
|
|
183
214
|
{ name: 'keccak', padding: KECCAK_PADDING, bits: BITS, createMethod: createMethod },
|
|
184
215
|
{ name: 'sha3', padding: PADDING, bits: BITS, createMethod: createMethod },
|
|
185
216
|
{ name: 'shake', padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod },
|
|
186
217
|
{ name: 'cshake', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createCshakeMethod },
|
|
187
|
-
{ name: 'kmac', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createKmacMethod }
|
|
218
|
+
{ name: 'kmac', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createKmacMethod },
|
|
219
|
+
{ name: 'tuplehash', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: function (bits, padding) {
|
|
220
|
+
return createTupleHashMethod(bits, padding, false);
|
|
221
|
+
}},
|
|
222
|
+
{ name: 'tuplehashxof', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: function (bits, padding) {
|
|
223
|
+
return createTupleHashMethod(bits, padding, true);
|
|
224
|
+
}}
|
|
188
225
|
];
|
|
189
226
|
|
|
190
227
|
var methods = {}, methodNames = [];
|
|
@@ -298,7 +335,7 @@ var sha3$1 = {exports: {}};
|
|
|
298
335
|
} else {
|
|
299
336
|
bytes.unshift(n);
|
|
300
337
|
}
|
|
301
|
-
|
|
338
|
+
Keccak.prototype.update.call(this, bytes);
|
|
302
339
|
return bytes.length;
|
|
303
340
|
};
|
|
304
341
|
|
|
@@ -325,7 +362,7 @@ var sha3$1 = {exports: {}};
|
|
|
325
362
|
bytes = length;
|
|
326
363
|
}
|
|
327
364
|
bytes += this.encode(bytes * 8);
|
|
328
|
-
|
|
365
|
+
Keccak.prototype.update.call(this, str);
|
|
329
366
|
return bytes;
|
|
330
367
|
};
|
|
331
368
|
|
|
@@ -337,7 +374,7 @@ var sha3$1 = {exports: {}};
|
|
|
337
374
|
var paddingBytes = (w - bytes % w) % w;
|
|
338
375
|
var zeros = [];
|
|
339
376
|
zeros.length = paddingBytes;
|
|
340
|
-
|
|
377
|
+
Keccak.prototype.update.call(this, zeros);
|
|
341
378
|
return this;
|
|
342
379
|
};
|
|
343
380
|
|
|
@@ -466,7 +503,107 @@ var sha3$1 = {exports: {}};
|
|
|
466
503
|
Kmac.prototype = new Keccak();
|
|
467
504
|
|
|
468
505
|
Kmac.prototype.finalize = function () {
|
|
469
|
-
|
|
506
|
+
if (!this.finalized) {
|
|
507
|
+
this.encode(this.outputBits, true);
|
|
508
|
+
}
|
|
509
|
+
return Keccak.prototype.finalize.call(this);
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
function TupleHash(bits, padding, outputBits, xof) {
|
|
513
|
+
Keccak.call(this, bits, padding, outputBits);
|
|
514
|
+
this.xof = !!xof;
|
|
515
|
+
this.inputActive = false;
|
|
516
|
+
this.inputBytesRemaining = 0;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
TupleHash.prototype = new Keccak();
|
|
520
|
+
|
|
521
|
+
TupleHash.prototype.getMessageByteLength = function (message) {
|
|
522
|
+
var result = formatMessage(message);
|
|
523
|
+
message = result[0];
|
|
524
|
+
if (!result[1]) {
|
|
525
|
+
return message.length;
|
|
526
|
+
}
|
|
527
|
+
var bytes = 0;
|
|
528
|
+
for (var i = 0; i < message.length; ++i) {
|
|
529
|
+
var code = message.charCodeAt(i);
|
|
530
|
+
if (code < 0x80) {
|
|
531
|
+
bytes += 1;
|
|
532
|
+
} else if (code < 0x800) {
|
|
533
|
+
bytes += 2;
|
|
534
|
+
} else if (code < 0xd800 || code >= 0xe000) {
|
|
535
|
+
bytes += 3;
|
|
536
|
+
} else {
|
|
537
|
+
++i;
|
|
538
|
+
bytes += 4;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return bytes;
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
TupleHash.prototype.beginInput = function (byteLength) {
|
|
545
|
+
if (this.finalized) {
|
|
546
|
+
throw new Error(FINALIZE_ERROR);
|
|
547
|
+
}
|
|
548
|
+
if (this.inputActive) {
|
|
549
|
+
throw new Error(TUPLE_INCOMPLETE_ERROR);
|
|
550
|
+
}
|
|
551
|
+
if (typeof byteLength !== 'number' || !isFinite(byteLength) || byteLength < 0 ||
|
|
552
|
+
Math.floor(byteLength) !== byteLength || byteLength > 0x0fffffff) {
|
|
553
|
+
throw new Error(TUPLE_BYTE_LENGTH_ERROR);
|
|
554
|
+
}
|
|
555
|
+
this.encode(byteLength * 8, false);
|
|
556
|
+
if (byteLength === 0) {
|
|
557
|
+
this.inputActive = false;
|
|
558
|
+
this.inputBytesRemaining = 0;
|
|
559
|
+
} else {
|
|
560
|
+
this.inputActive = true;
|
|
561
|
+
this.inputBytesRemaining = byteLength;
|
|
562
|
+
}
|
|
563
|
+
return this;
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
TupleHash.prototype.updateChunk = function (message) {
|
|
567
|
+
if (this.finalized) {
|
|
568
|
+
throw new Error(FINALIZE_ERROR);
|
|
569
|
+
}
|
|
570
|
+
if (!this.inputActive) {
|
|
571
|
+
throw new Error(TUPLE_ACTIVE_ERROR);
|
|
572
|
+
}
|
|
573
|
+
var byteLength = this.getMessageByteLength(message);
|
|
574
|
+
if (byteLength > this.inputBytesRemaining) {
|
|
575
|
+
throw new Error(TUPLE_LENGTH_ERROR);
|
|
576
|
+
}
|
|
577
|
+
Keccak.prototype.update.call(this, message);
|
|
578
|
+
this.inputBytesRemaining -= byteLength;
|
|
579
|
+
if (this.inputBytesRemaining === 0) {
|
|
580
|
+
this.inputActive = false;
|
|
581
|
+
}
|
|
582
|
+
return this;
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
TupleHash.prototype.update = function (message) {
|
|
586
|
+
if (this.finalized) {
|
|
587
|
+
throw new Error(FINALIZE_ERROR);
|
|
588
|
+
}
|
|
589
|
+
if (this.inputActive) {
|
|
590
|
+
throw new Error(TUPLE_INCOMPLETE_ERROR);
|
|
591
|
+
}
|
|
592
|
+
var byteLength = this.getMessageByteLength(message);
|
|
593
|
+
this.beginInput(byteLength);
|
|
594
|
+
if (byteLength === 0) {
|
|
595
|
+
return this;
|
|
596
|
+
}
|
|
597
|
+
return this.updateChunk(message);
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
TupleHash.prototype.finalize = function () {
|
|
601
|
+
if (this.inputActive) {
|
|
602
|
+
throw new Error(TUPLE_INCOMPLETE_ERROR);
|
|
603
|
+
}
|
|
604
|
+
if (!this.finalized) {
|
|
605
|
+
this.encode(this.xof ? 0 : this.outputBits, true);
|
|
606
|
+
}
|
|
470
607
|
return Keccak.prototype.finalize.call(this);
|
|
471
608
|
};
|
|
472
609
|
|
|
@@ -696,7 +833,16 @@ const {
|
|
|
696
833
|
kmac_128,
|
|
697
834
|
kmac_256,
|
|
698
835
|
kmac128,
|
|
699
|
-
kmac256
|
|
836
|
+
kmac256,
|
|
837
|
+
|
|
838
|
+
tuplehash_128,
|
|
839
|
+
tuplehash_256,
|
|
840
|
+
tuplehash128,
|
|
841
|
+
tuplehash256,
|
|
842
|
+
tuplehashxof_128,
|
|
843
|
+
tuplehashxof_256,
|
|
844
|
+
tuplehashxof128,
|
|
845
|
+
tuplehashxof256
|
|
700
846
|
} = sha3;
|
|
701
847
|
|
|
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 };
|
|
848
|
+
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, 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,11 @@ 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 tuplehash_128: TupleHashMethod;
|
|
409
|
+
export var tuplehash_256: TupleHashMethod;
|
|
410
|
+
export var tuplehash128: TupleHashMethod;
|
|
411
|
+
export var tuplehash256: TupleHashMethod;
|
|
412
|
+
export var tuplehashxof_128: TupleHashMethod;
|
|
413
|
+
export var tuplehashxof_256: TupleHashMethod;
|
|
414
|
+
export var tuplehashxof128: TupleHashMethod;
|
|
415
|
+
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.11.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,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* [js-sha3]{@link https://github.com/emn178/js-sha3}
|
|
3
3
|
*
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.11.0
|
|
5
5
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
6
6
|
* @copyright Chen, Yi-Cyuan 2015-2023
|
|
7
7
|
* @license MIT
|
|
@@ -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) {
|
|
@@ -171,12 +175,45 @@
|
|
|
171
175
|
return createOutputMethods(method, createKmacOutputMethod, bits, padding);
|
|
172
176
|
};
|
|
173
177
|
|
|
178
|
+
var createTupleHashOutputMethod = function (bits, padding, xof, outputType) {
|
|
179
|
+
return function (inputs, outputBits, s) {
|
|
180
|
+
return methods[(xof ? 'tuplehashxof' : 'tuplehash') + bits].update(inputs, outputBits, s)[outputType]();
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
var createTupleHashMethod = function (bits, padding, xof) {
|
|
185
|
+
var w = CSHAKE_BYTEPAD[bits];
|
|
186
|
+
var method = createTupleHashOutputMethod(bits, padding, xof, 'hex');
|
|
187
|
+
method.create = function (outputBits, s) {
|
|
188
|
+
return new TupleHash(bits, padding, outputBits, xof).bytepad(['TupleHash', s], w);
|
|
189
|
+
};
|
|
190
|
+
method.update = function (inputs, outputBits, s) {
|
|
191
|
+
if (!isArray(inputs)) {
|
|
192
|
+
throw new Error(INPUT_ERROR);
|
|
193
|
+
}
|
|
194
|
+
var hash = method.create(outputBits, s);
|
|
195
|
+
for (var i = 0; i < inputs.length; ++i) {
|
|
196
|
+
hash.update(inputs[i]);
|
|
197
|
+
}
|
|
198
|
+
return hash;
|
|
199
|
+
};
|
|
200
|
+
return createOutputMethods(method, function (b, p, outputType) {
|
|
201
|
+
return createTupleHashOutputMethod(b, p, xof, outputType);
|
|
202
|
+
}, bits, padding);
|
|
203
|
+
};
|
|
204
|
+
|
|
174
205
|
var algorithms = [
|
|
175
206
|
{ name: 'keccak', padding: KECCAK_PADDING, bits: BITS, createMethod: createMethod },
|
|
176
207
|
{ name: 'sha3', padding: PADDING, bits: BITS, createMethod: createMethod },
|
|
177
208
|
{ name: 'shake', padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod },
|
|
178
209
|
{ name: 'cshake', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createCshakeMethod },
|
|
179
|
-
{ name: 'kmac', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createKmacMethod }
|
|
210
|
+
{ name: 'kmac', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createKmacMethod },
|
|
211
|
+
{ name: 'tuplehash', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: function (bits, padding) {
|
|
212
|
+
return createTupleHashMethod(bits, padding, false);
|
|
213
|
+
}},
|
|
214
|
+
{ name: 'tuplehashxof', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: function (bits, padding) {
|
|
215
|
+
return createTupleHashMethod(bits, padding, true);
|
|
216
|
+
}}
|
|
180
217
|
];
|
|
181
218
|
|
|
182
219
|
var methods = {}, methodNames = [];
|
|
@@ -290,7 +327,7 @@
|
|
|
290
327
|
} else {
|
|
291
328
|
bytes.unshift(n);
|
|
292
329
|
}
|
|
293
|
-
|
|
330
|
+
Keccak.prototype.update.call(this, bytes);
|
|
294
331
|
return bytes.length;
|
|
295
332
|
};
|
|
296
333
|
|
|
@@ -317,7 +354,7 @@
|
|
|
317
354
|
bytes = length;
|
|
318
355
|
}
|
|
319
356
|
bytes += this.encode(bytes * 8);
|
|
320
|
-
|
|
357
|
+
Keccak.prototype.update.call(this, str);
|
|
321
358
|
return bytes;
|
|
322
359
|
};
|
|
323
360
|
|
|
@@ -329,7 +366,7 @@
|
|
|
329
366
|
var paddingBytes = (w - bytes % w) % w;
|
|
330
367
|
var zeros = [];
|
|
331
368
|
zeros.length = paddingBytes;
|
|
332
|
-
|
|
369
|
+
Keccak.prototype.update.call(this, zeros);
|
|
333
370
|
return this;
|
|
334
371
|
};
|
|
335
372
|
|
|
@@ -458,7 +495,107 @@
|
|
|
458
495
|
Kmac.prototype = new Keccak();
|
|
459
496
|
|
|
460
497
|
Kmac.prototype.finalize = function () {
|
|
461
|
-
|
|
498
|
+
if (!this.finalized) {
|
|
499
|
+
this.encode(this.outputBits, true);
|
|
500
|
+
}
|
|
501
|
+
return Keccak.prototype.finalize.call(this);
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
function TupleHash(bits, padding, outputBits, xof) {
|
|
505
|
+
Keccak.call(this, bits, padding, outputBits);
|
|
506
|
+
this.xof = !!xof;
|
|
507
|
+
this.inputActive = false;
|
|
508
|
+
this.inputBytesRemaining = 0;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
TupleHash.prototype = new Keccak();
|
|
512
|
+
|
|
513
|
+
TupleHash.prototype.getMessageByteLength = function (message) {
|
|
514
|
+
var result = formatMessage(message);
|
|
515
|
+
message = result[0];
|
|
516
|
+
if (!result[1]) {
|
|
517
|
+
return message.length;
|
|
518
|
+
}
|
|
519
|
+
var bytes = 0;
|
|
520
|
+
for (var i = 0; i < message.length; ++i) {
|
|
521
|
+
var code = message.charCodeAt(i);
|
|
522
|
+
if (code < 0x80) {
|
|
523
|
+
bytes += 1;
|
|
524
|
+
} else if (code < 0x800) {
|
|
525
|
+
bytes += 2;
|
|
526
|
+
} else if (code < 0xd800 || code >= 0xe000) {
|
|
527
|
+
bytes += 3;
|
|
528
|
+
} else {
|
|
529
|
+
++i;
|
|
530
|
+
bytes += 4;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return bytes;
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
TupleHash.prototype.beginInput = function (byteLength) {
|
|
537
|
+
if (this.finalized) {
|
|
538
|
+
throw new Error(FINALIZE_ERROR);
|
|
539
|
+
}
|
|
540
|
+
if (this.inputActive) {
|
|
541
|
+
throw new Error(TUPLE_INCOMPLETE_ERROR);
|
|
542
|
+
}
|
|
543
|
+
if (typeof byteLength !== 'number' || !isFinite(byteLength) || byteLength < 0 ||
|
|
544
|
+
Math.floor(byteLength) !== byteLength || byteLength > 0x0fffffff) {
|
|
545
|
+
throw new Error(TUPLE_BYTE_LENGTH_ERROR);
|
|
546
|
+
}
|
|
547
|
+
this.encode(byteLength * 8, false);
|
|
548
|
+
if (byteLength === 0) {
|
|
549
|
+
this.inputActive = false;
|
|
550
|
+
this.inputBytesRemaining = 0;
|
|
551
|
+
} else {
|
|
552
|
+
this.inputActive = true;
|
|
553
|
+
this.inputBytesRemaining = byteLength;
|
|
554
|
+
}
|
|
555
|
+
return this;
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
TupleHash.prototype.updateChunk = function (message) {
|
|
559
|
+
if (this.finalized) {
|
|
560
|
+
throw new Error(FINALIZE_ERROR);
|
|
561
|
+
}
|
|
562
|
+
if (!this.inputActive) {
|
|
563
|
+
throw new Error(TUPLE_ACTIVE_ERROR);
|
|
564
|
+
}
|
|
565
|
+
var byteLength = this.getMessageByteLength(message);
|
|
566
|
+
if (byteLength > this.inputBytesRemaining) {
|
|
567
|
+
throw new Error(TUPLE_LENGTH_ERROR);
|
|
568
|
+
}
|
|
569
|
+
Keccak.prototype.update.call(this, message);
|
|
570
|
+
this.inputBytesRemaining -= byteLength;
|
|
571
|
+
if (this.inputBytesRemaining === 0) {
|
|
572
|
+
this.inputActive = false;
|
|
573
|
+
}
|
|
574
|
+
return this;
|
|
575
|
+
};
|
|
576
|
+
|
|
577
|
+
TupleHash.prototype.update = function (message) {
|
|
578
|
+
if (this.finalized) {
|
|
579
|
+
throw new Error(FINALIZE_ERROR);
|
|
580
|
+
}
|
|
581
|
+
if (this.inputActive) {
|
|
582
|
+
throw new Error(TUPLE_INCOMPLETE_ERROR);
|
|
583
|
+
}
|
|
584
|
+
var byteLength = this.getMessageByteLength(message);
|
|
585
|
+
this.beginInput(byteLength);
|
|
586
|
+
if (byteLength === 0) {
|
|
587
|
+
return this;
|
|
588
|
+
}
|
|
589
|
+
return this.updateChunk(message);
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
TupleHash.prototype.finalize = function () {
|
|
593
|
+
if (this.inputActive) {
|
|
594
|
+
throw new Error(TUPLE_INCOMPLETE_ERROR);
|
|
595
|
+
}
|
|
596
|
+
if (!this.finalized) {
|
|
597
|
+
this.encode(this.xof ? 0 : this.outputBits, true);
|
|
598
|
+
}
|
|
462
599
|
return Keccak.prototype.finalize.call(this);
|
|
463
600
|
};
|
|
464
601
|
|
package/src/sha3.mjs
CHANGED
|
@@ -28,7 +28,16 @@ export const {
|
|
|
28
28
|
kmac_128,
|
|
29
29
|
kmac_256,
|
|
30
30
|
kmac128,
|
|
31
|
-
kmac256
|
|
31
|
+
kmac256,
|
|
32
|
+
|
|
33
|
+
tuplehash_128,
|
|
34
|
+
tuplehash_256,
|
|
35
|
+
tuplehash128,
|
|
36
|
+
tuplehash256,
|
|
37
|
+
tuplehashxof_128,
|
|
38
|
+
tuplehashxof_256,
|
|
39
|
+
tuplehashxof128,
|
|
40
|
+
tuplehashxof256
|
|
32
41
|
} = sha3;
|
|
33
42
|
|
|
34
43
|
export default sha3;
|