-
Notifications
You must be signed in to change notification settings - Fork 1
/
mod.ts
127 lines (105 loc) · 18.3 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
const ENCODER = new TextEncoder
const HEAP = 16 * 1024
const SEED_LENGTH = 8
const DEFAULT_SEED = new Uint8Array(SEED_LENGTH) // default to zeros
const DIGEST_DATA = new Uint8Array(BigUint64Array.BYTES_PER_ELEMENT)
const DIGEST_VIEW = new DataView(DIGEST_DATA.buffer)
type Data = Uint8Array | string
type Digests = Uint8Array | bigint | string
type InternalHasher = {
Hash_GetBuffer: () => number,
Hash_Init: () => undefined,
Hash_Update: (length: number) => any,
Hash_Final: () => undefined
}
export interface Hasher {
reset: () => Hasher
reseed: (seed: Uint8Array) => Hasher
update: (data: Data) => Hasher
digest: (format?: string) => Digests
hash: (data: Data, format?: string) => Digests
}
class XXHasher implements Hasher {
private internal: InternalHasher
private memory: Uint8Array
private seed: Uint8Array
constructor(instance: WebAssembly.Instance, seed: Uint8Array) {
this.internal = instance.exports as InternalHasher
this.memory = new Uint8Array(
(instance.exports.memory as WebAssembly.Memory).buffer,
this.internal.Hash_GetBuffer(), HEAP
)
this.seed = seed
this.reset()
}
reset() {
this.memory.set(this.seed)
this.internal.Hash_Init()
return this
}
reseed(seed: Uint8Array) {
this.seed = seed
return this.reset()
}
update(data: Data) {
if (typeof data === 'string') data = ENCODER.encode(data)
let updated = 0
while (updated < data.length) {
const block = data.subarray(updated, updated + HEAP)
this.memory.set(block)
this.internal.Hash_Update(block.length)
updated += block.length
}
return this
}
digest(format: string = 'raw'): Digests {
this.internal.Hash_Final()
const length = DIGEST_DATA.byteLength
if (format === 'bigint') {
DIGEST_DATA.set(this.memory.subarray(0, length))
// read digest bytes as a little-endian uint64
return DIGEST_VIEW.getBigUint64(0, true)
}
if (format === 'hex') {
// return digest as a hex string
return [...this.memory.subarray(0, length)].map(
b => b.toString(16).padStart(2, '0')
).join('')
}
// return a copy of the raw digest bytes
return this.memory.slice(0, length)
}
hash(data: Data, format: string = 'raw'): Digests {
return this.reset().update(data).digest(format)
}
}
// xxHash64 WASM implementation from https://github.com/Daninet/hash-wasm/blob/master/src/xxhash64.c (4.10.0)
const WASM2 = "AGFzbQEAAAABDANgAAF/YAAAYAF/AAMHBgABAgEAAQUEAQECAgYOAn8BQdCJBQt/AEGACAsHcAgGbWVtb3J5AgAOSGFzaF9HZXRCdWZmZXIAAAlIYXNoX0luaXQAAQtIYXNoX1VwZGF0ZQACCkhhc2hfRmluYWwAAw1IYXNoX0dldFN0YXRlAAQOSGFzaF9DYWxjdWxhdGUABQpTVEFURV9TSVpFAwEK9A8GBQBBgAkLYwEBfkEAQgA3A8iJAUEAQQApA4AJIgA3A5CJAUEAIABC+erQ0OfJoeThAHw3A5iJAUEAIABCz9bTvtLHq9lCfDcDiIkBQQAgAELW64Lu6v2J9eAAfDcDgIkBQQBBADYCwIkBC70IAwV/BH4CfwJAIABFDQBBAEEAKQPIiQEgAK18NwPIiQECQEEAKALAiQEiASAAakEfSw0AAkACQCAAQQNxIgINAEGACSEDIAAhAQwBCyAAQXxxIQFBgAkhAwNAQQBBACgCwIkBIgRBAWo2AsCJASAEQaCJAWogAy0AADoAACADQQFqIQMgAkF/aiICDQALCyAAQQRJDQEDQEEAQQAoAsCJASICQQFqNgLAiQEgAkGgiQFqIAMtAAA6AAAgA0EBai0AACECQQBBACgCwIkBIgRBAWo2AsCJASAEQaCJAWogAjoAACADQQJqLQAAIQJBAEEAKALAiQEiBEEBajYCwIkBIARBoIkBaiACOgAAIANBA2otA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AkLBgBBgIkBCwIACwsLAQBBgAgLBFAAAAA="
// xxHash3 WASM implementation from https://github.com/Daninet/hash-wasm/blob/master/src/xxhash3.c (4.10.0)
const WASM3 = "AGFzbQEAAAABNAhgAAF/YAR/f39/AGAHf39/f39/fwBgBH9+fn4BfmAEf39/fgF+YAN/f34BfmAAAGABfwADDg0AAQIDBAUFBQYHBgAGBQQBAQICBg4CfwFBwI4FC38AQcAJCwdwCAZtZW1vcnkCAA5IYXNoX0dldEJ1ZmZlcgAACUhhc2hfSW5pdAAIC0hhc2hfVXBkYXRlAAkKSGFzaF9GaW5hbAAKDUhhc2hfR2V0U3RhdGUACw5IYXNoX0NhbGN1bGF0ZQAMClNUQVRFX1NJWkUDAQrNQg0FAEGACgvvAwEQfgJAIANFDQAgAUE4aiEBIAJBOGohAiAAKQMwIQQgACkDOCEFIAApAyAhBiAAKQMoIQcgACkDECEIIAApAxghCSAAKQMAIQogACkDCCELA0AgByABQWhqKQMAIgx8IAJBcGopAwAgAUFwaikDACINhSIHQiCIIAdC/////w+DfnwhByAJIAFBWGopAwAiDnwgAkFgaikDACABQWBqKQMAIg+FIglCIIggCUL/////D4N+fCEJIAsgAUFIaikDACIQfCACQVBqKQMAIAFBUGopAwAiEYUiC0IgiCALQv////8Pg358IQsgAkF4aikDACABQXhqKQMAIhKFIhNCIIggE0L/////D4N+IAR8IAEpAwAiE3whBCACQWhqKQMAIAyFIgxCIIggDEL/////D4N+IAZ8IA18IQYgAkFYaikDACAOhSIMQiCIIAxC/////w+DfiAIfCAPfCEIIAJBSGopAwAgEIUiDEIgiCAMQv////8Pg34gCnwgEXwhCiAFIBJ8IAIpAwAgE4UiBUIgiCAFQv////8Pg358IQUgAUHAAGohASACQQhqIQIgA0F/aiIDDQALIAAgCTcDGCAAIAo3AwAgACALNwMIIAAgBzcDKCAAIAg3AxAgACAFNwM4IAAgBjcDICAAIAQ3AzALC94CAgF/AX4CQCACIAEoAgAiB2siAiAESw0AIAAgAyAFIAdBA3RqIAIQASAAIAUgBmoiBykDACAAKQMAIghCL4iFIAiFQrHz3fEJfjcDACAAIAcpAwggACkDCCIIQi+IhSAIhUKx893xCX43AwggACAHKQMQIAApAxAiCEIviIUgCIVCsfPd8Ql+NwMQIAAgBykDGCAAKQMYIghCL4iFIAiFQrHz3fEJfjcDGCAAIAcpAyAgACkDICIIQi+IhSAIhUKx893xCX43AyAgACAHKQMoIAApAygiCEIviIUgCIVCsfPd8Ql+NwMoIAAgBykDMCAAKQMwIghCL4iFIAiFQrHz3fEJfjcDMCAAIAcpAzggACkDOCIIQi+IhSAIhUKx893xCX43AzggACADIAJBBnRqIAUgBCACayIHEAEgASAHNgIADwsgACADIAUgB0EDdGogBBABIAEgByAEajYCAAuFAQEBfyACIAGFIAOnIgRBGHQgBEGA/gNxQQh0ciAEQQh2QYD+A3EgBEEYdnJyrUIghiADhX1BADUCgIwBQiCGIABB/IsBajUCAISFIgNCMYkgA0IYiYUgA4VCpb7j9NGMh9mff34iA0IjiCAArXwgA4VCpb7j9NGMh9mff34iA0IciCADhQtnACACIAFzrSADfCIDQiGIQQAtAICMAUEQdCAAQQh0ciAAQQF2QYCMAWotAABBGHRyIABB/4sBai0AAHKthSADhULP1tO+0ser2UJ+IgNCHYggA4VC+fPd8Zn2masWfiIDQiCIIAOFC4kDAQR+AkAgAEEJSQ0AQQApA4CMASABKQMgIAEpAxiFIAJ8hSIDQjiGIANCgP4Dg0IohoQgA0KAgPwHg0IYhiADQoCAgPgPg0IIhoSEIANCCIhCgICA+A+DIANCGIhCgID8B4OEIANCKIhCgP4DgyADQjiIhISEIACtfCAAQfiLAWopAwAgASkDMCABKQMohSACfYUiAnwgAkL/////D4MiBCADQiCIIgV+IgZC/////w+DIAJCIIgiAiADQv////8PgyIDfnwgBCADfiIDQiCIfCIEQiCGIANC/////w+DhCAGQiCIIAIgBX58IARCIIh8hXwiA0IliCADhUL5893xmfKZqxZ+IgNCIIggA4UPCwJAIABBBEkNACAAIAFBCGopAwAgAUEQaikDACACEAMPCwJAIABFDQAgACABKAIAIAFBBGooAgAgAhAEDwsgASkDOCABKQNAhSAChSIDQiGIIAOFQs/W077Sx6vZQn4iA0IdiCADhUL5893xmfaZqxZ+IgNCIIggA4UL3ggBBn4gAK1Ch5Wvr5i23puef34hAwJAIABBIUkNAAJAIABBwQBJDQACQCAAQeEASQ0AIAEpA2ggAn1BACkDuIwBhSIEQv////8PgyIFIAEpA2AgAnxBACkDsIwBhSIGQiCIIgd+IghC/////w+DIARCIIgiBCAGQv////8PgyIGfnwgBSAGfiIFQiCIfCIGQiCGIAVC/////w+DhCAIQiCIIAQgB358IAZCIIh8hSADfCABKQN4IAJ9IABByIsBaikDAIUiA0L/////D4MiBCABKQNwIAJ8IABBwIsBaikDAIUiBUIgiCIGfiIHQv////8PgyADQiCIIgMgBUL/////D4MiBX58IAQgBX4iBEIgiHwiBUIghiAEQv////8Pg4QgB0IgiCADIAZ+fCAFQiCIfIV8IQMLIAEpA0ggAn1BACkDqIwBhSIEQv////8PgyIFIAEpA0AgAnxBACkDoIwBhSIGQiCIIgd+IghC/////w+DIARCIIgiBCAGQv////8PgyIGfnwgBSAGfiIFQiCIfCIGQiCGIAVC/////w+DhCAIQiCIIAQgB358IAZCIIh8hSADfCABKQNYIAJ9IABB2IsBaikDAIUiA0L/////D4MiBCABKQNQIAJ8IABB0IsBaikDAIUiBUIgiCIGfiIHQv////8PgyADQiCIIgMgBUL/////D4MiBX58IAQgBX4iBEIgiHwiBUIghiAEQv////8Pg4QgB0IgiCADIAZ+fCAFQiCIfIV8IQMLIAEpAyggAn1BACkDmIwBhSIEQv////8PgyIFIAEpAyAgAnxBACkDkIwBhSIGQiCIIgd+IghC/////w+DIARCIIgiBCAGQv////8PgyIGfnwgBSAGfiIFQiCIfCIGQiCGIAVC/////w+DhCAIQiCIIAQgB358IAZCIIh8hSADfCABKQM4IAJ9IABB6IsBaikDAIUiA0L/////D4MiBCABKQMwIAJ8IABB4IsBaikDAIUiBUIgiCIGfiIHQv////8PgyADQiCIIgMgBUL/////D4MiBX58IAQgBX4iBEIgiHwiBUIghiAEQv////8Pg4QgB0IgiCADIAZ+fCAFQiCIfIV8IQMLIAEpAwggAn1BACkDiIwBhSIEQv////8PgyIFIAEpAwAgAnxBACkDgIwBhSIGQiCIIgd+IghC/////w+DIARCIIgiBCAGQv////8PgyIGfnwgBSAGfiIFQiCIfCIGQiCGIAVC/////w+DhCAIQiCIIAQgB358IAZCIIh8hSADfCABKQMYIAJ9IABB+IsBaikDAIUiA0L/////D4MiBCABKQMQIAJ8IABB8IsBaikDAIUiAkIgiCIFfiIGQv////8PgyADQiCIIgMgAkL/////D4MiAn58IAQgAn4iAkIgiHwiBEIghiACQv////8Pg4QgBkIgiCADIAV+fCAEQiCIfIV8IgJCJYggAoVC+fPd8ZnymasWfiICQiCIIAKFC/wKBAF/BX4CfwF+QQAhAyABKQN4IAJ9QQApA/iMAYUiBEL/////D4MiBSABKQNwIAJ8QQApA/CMAYUiBkIgiCIHfiIIQv////8PgyAEQiCIIgQgBkL/////D4MiBn58IAUgBn4iBUIgiHwiBkIghiAFQv////8Pg4QgCEIgiCAEIAd+fCAGQiCIfIUgASkDaCACfUEAKQPojAGFIgRC/////w+DIgUgASkDYCACfEEAKQPgjAGFIgZCIIgiB34iCEL/////D4MgBEIgiCIEIAZC/////w+DIgZ+fCAFIAZ+IgVCIIh8IgZCIIYgBUL/////D4OEIAhCIIggBCAHfnwgBkIgiHyFIAEpA1ggAn1BACkD2IwBhSIEQv////8PgyIFIAEpA1AgAnxBACkD0IwBhSIGQiCIIgd+IghC/////w+DIARCIIgiBCAGQv////8PgyIGfnwgBSAGfiIFQiCIfCIGQiCGIAVC/////w+DhCAIQiCIIAQgB358IAZCIIh8hSABKQNIIAJ9QQApA8iMAYUiBEL/////D4MiBSABKQNAIAJ8QQApA8CMAYUiBkIgiCIHfiIIQv////8PgyAEQiCIIgQgBkL/////D4MiBn58IAUgBn4iBUIgiHwiBkIghiAFQv////8Pg4QgCEIgiCAEIAd+fCAGQiCIfIUgASkDOCACfUEAKQO4jAGFIgRC/////w+DIgUgASkDMCACfEEAKQOwjAGFIgZCIIgiB34iCEL/////D4MgBEIgiCIEIAZC/////w+DIgZ+fCAFIAZ+IgVCIIh8IgZCIIYgBUL/////D4OEIAhCIIggBCAHfnwgBkIgiHyFIAEpAyggAn1BACkDqIwBhSIEQv////8PgyIFIAEpAyAgAnxBACkDoIwBhSIGQiCIIgd+IghC/////w+DIARCIIgiBCAGQv////8PgyIGfnwgBSAGfiIFQiCIfCIGQiCGIAVC/////w+DhCAIQiCIIAQgB358IAZCIIh8hSABKQMYIAJ9QQApA5iMAYUiBEL/////D4MiBSABKQMQIAJ8QQApA5CMAYUiBkIgiCIHfiIIQv////8PgyAEQiCIIgQgBkL/////D4MiBn58IAUgBn4iBUIgiHwiBkIghiAFQv////8Pg4QgCEIgiCAEIAd+fCAGQiCIfIUgASkDCCACfUEAKQOIjAGFIgRC/////w+DIgUgASkDACACfEEAKQOAjAGFIgZCIIgiB34iCEL/////D4MgBEIgiCIEIAZC/////w+DIgZ+fCAFIAZ+IgVCIIh8IgZCIIYgBUL/////D4OEIAhCIIggBCAHfnwgBkIgiHyFIACtQoeVr6+Ytt6bnn9+fHx8fHx8fHwiBEIliCAEhUL5893xmfKZqxZ+IgRCIIggBIUhBAJAIABBkAFIDQAgAEEEdkF4aiEJA0AgASADaiIKQQtqKQMAIAJ9IANBiI0BaikDAIUiBUL/////D4MiBiAKQQNqKQMAIAJ8IANBgI0BaikDAIUiB0IgiCIIfiILQv////8PgyAFQiCIIgUgB0L/////D4MiB358IAYgB34iBkIgiHwiB0IghiAGQv////8Pg4QgC0IgiCAFIAh+fCAHQiCIfIUgBHwhBCADQRBqIQMgCUF/aiIJDQALCyABKQN/IAJ9IABB+IsBaikDAIUiBUL/////D4MiBiABKQN3IAJ8IABB8IsBaikDAIUiAkIgiCIHfiIIQv////8PgyAFQiCIIgUgAkL/////D4MiAn58IAYgAn4iAkIgiHwi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AjgEiASAAaiICQYACSw0AIAFBgIwBaiEDQYAKIQQCQCAAQQhPDQAgACEBDAILAkACQCAAQXhqIgVBA3ZBAWpBB3EiBg0AQYAKIQQgACEBDAELIAZBA3QhAUGACiEEA0AgAyAEKQMANwMAIANBCGohAyAEQQhqIQQgBkF/aiIGDQALIAAgAWshAQsgBUE4SQ0BA0AgAyAEKQMANwMAIANBCGogBEEIaikDADcDACADQRBqIARBEGopAwA3AwAgA0EYaiAEQRhqKQMANwMAIANBIGogBEEgaikDADcDACADQShqIARBKGopAwA3AwAgA0EwaiAEQTBqKQMANwMAIANBOGogBEE4aikDADcDACADQcAAaiEDIARBwABqIQQgAUFAaiIBQQdLDQAMAgsLQYAKIQQgAEGACmohBUEAKAKwjgEiA0HAigEgAxshBgJAIAFFDQAgAUGAjAFqIQNBgAohBAJAAkBBgAIgAWsiB0EITw0AIAchAAwBCwJAAkBB+AEgAWsiCEEDdkEBakEHcSICDQBBgAohBCAHIQAMAQtBgAohBCACQQN0IgAhAgNAIAMgBCkDADcDACADQQhqIQMgBEEIaiEEIAJBeGoiAg0AC0GAAiABIABqayEACyAIQThJDQADQCADIAQpAwA3AwAgA0EIaiAEQQhqKQMANwMAIANBEGogBEEQaikDADcDACADQRhqIARBGGopAwA3AwAgA0EgaiAEQSBqKQMANwMAIANBKGogBEEoaikDADcDACADQTBqIARBMGopAwA3AwAgA0E4aiAEQThqKQMANwMAIANBwABqIQMgBEHAAGohBCAAQUBqIgBBB0sNAAsLAkAgAEUNAAJAAkAgAEEHcSICDQAgACEBDAELIABBeHEhAQNAIAMgBC0AADoAACADQQFqIQMgBEEBaiEEIAJBf2oiAg0ACwsgAEEISQ0AA0AgAyAEKQAANwAAIANBCGohAyAEQQhqIQQgAUF4aiIBDQALC0GAigFBiI4BQQAoApiOAUGAjAFBBCAGQQAoApyOARACQQBBADYCgI4BIAdBgApqIQQLAkAgBEGAAmogBU8NACAFQYB+aiEDA0BBgIoBQYiOAUEAKAKYjgEgBEEEIAZB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BaiEcIABBAWohACAfQX9qIh8NAAsLIAZBCEkNAANAIBwgACkAADcAACAcQQhqIRwgAEEIaiEAIB5BeGoiHg0ACwsgA0EAKAKcjgFqIgBBeWopAwAhCSAAQQlqKQMAIREgAEEZaikDACESIABBAWopAwAhCiAAQRFqKQMAIQwgAEEhaikDACEPIABBKWopAwAhEyACKQMAIRQgAikDECEVIAIpAyAhFiACKQMIIRcgAikDQCELIAIpA0ghDSACKQMYIRggAikDUCEOIAIpA1ghCCACKQMoIRkgAikDYCEQIAIpA2ghByACIAUgAikDcCIafCAAQTFqKQMAIAIpA3giBYUiG0IgiCAbQv////8Pg358NwM4IAIgBSATIBqFIhNCIIggE0L/////D4N+IAR8fDcDMCAZIBB8IA8gB4UiBEIgiCAEQv////8Pg358IQ8gGCAOfCAMIAiFIgRCIIggBEL/////D4N+fCEMIBcgC3wgCiANhSIEQiCIIARC/////w+DfnwhCiAHIBYgEiAQhSIEQiCIIARC/////w+Dfnx8IRAgCCAVIBEgDoUiBEIgiCAEQv////8Pg358fCEIIA0gFCAJIAuFIgRCIIggBEL/////D4N+fHwhBwsgAykDQyACKQM4hSIEQv////8PgyIFIAMpAzsgAikDMIUiC0IgiCINfiIOQv////8PgyAEQiCIIgQgC0L/////D4MiC358IAUgC34iBUIgiHwiC0IghiAFQv////8Pg4QgDkIgiCAEIA1+fCALQiCIfIUgAykDMyAPhSIEQv////8PgyIFIAMpAysgEIUiC0IgiCINfiIOQv////8PgyAEQiCIIgQgC0L/////D4MiC358IAUgC34iBUIgiHwiC0IghiAFQv////8Pg4QgDkIgiCAEIA1+fCALQiCIfIUgAykDIyAMhSIEQv////8PgyIFIAMpAxsgCIUiC0IgiCINfiIOQv////8PgyAEQiCIIgQgC0L/////D4MiC358IAUgC34iBUIgiHwiC0IghiAFQv////8Pg4QgDkIgiCAEIA1+fCALQiCIfIUgAykDEyAKhSIEQv////8PgyIFIAMpAwsgB4UiC0IgiCINfiIOQv////8PgyAEQiCIIgQgC0L/////D4MiC358IAUgC34iBUIgiHwiC0IghiAFQv////8Pg4QgDkIgiCAEIA1+fCALQiCIfIVBACkDkI4BQoeVr6+Ytt6bnn9+fHx8fCIEQiWIIASFQvnz3fGZ8pmrFn4iBEIgiCAEhSEEDAELIASnIQACQEEAKQOgjgEiBFANAAJAIABBEEsNACAAQYAIIAQQBSEEDAILAkAgAEGAAUsNACAAQYAIIAQQBiEEDAILIABBgAggBBAHIQQMAQsCQCAAQRBLDQAgACADQgAQBSEEDAELAkAgAEGAAUsNACAAIANCABAGIQQMAQsgACADQgAQByEEC0EAIARCOIYgBEKA/gODQiiGhCAEQoCA/AeDQhiGIARCgICA+A+DQgiGhIQgBEIIiEKAgID4D4MgBEIYiEKAgPwHg4QgBEIoiEKA/gODIARCOIiEhIQ3A4AKIAEkAAsGAEGAigELAgALC8wBAQBBgAgLxAG4/mw5I6RLvnwBgSz3Ia0c3tRt6YOQl9tyQKSkt7NnH8t55k7MwOV4glrQfcz/ciG4CEZ090MkjuA1kOaBOiZMPChSu5HDAMuI0GWLG1Muo3FkSJeiDflOOBnvRqnerNio+nY/45w0P/ncu8fHC08dilHgS820WTHIn37J2XhzZOrFrIM00+vDxYGg//oTY+sXDd1Rt/DaSdMWVSYp1GieKxa+WH1HofyP+LjRetAxzkXLOo+VFgQor9f7yrtLQH5AAgAA"
function fromBase64(base64: string) {
return Uint8Array.from(atob(base64), char => char.charCodeAt(0))
}
const XXHash64 = WebAssembly.compile(fromBase64(WASM2))
const XXHash3 = WebAssembly.compile(fromBase64(WASM3))
type SeedData = Iterable<unknown>
function generateSeed(data: SeedData): Uint8Array {
const seed = new Uint8Array(SEED_LENGTH)
let index = 0
for (const item of data) seed[index++ % SEED_LENGTH] ^= item as number
return seed
}
async function construct(
code: WebAssembly.Module,
seedData?: SeedData
): Promise<Hasher> {
const instance = await WebAssembly.instantiate(code)
const seed = seedData ? generateSeed(seedData) : DEFAULT_SEED
return new XXHasher(instance, seed)
}
export async function create(seedData?: SeedData): Promise<Hasher> {
return construct(await XXHash64, seedData)
}
export async function create3(seedData?: SeedData): Promise<Hasher> {
return construct(await XXHash3, seedData)
}