neozipkit 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +400 -0
- package/contracts/Lock.sol +34 -0
- package/contracts/bytecode.txt +1 -0
- package/contracts/compile-contract.js +168 -0
- package/contracts/deploy/deploy-both-contracts.js +286 -0
- package/contracts/deploy/deploy-enhanced-contract.js +197 -0
- package/contracts/deploy/deploy-private-contract.js +190 -0
- package/contracts/deploy/deploy-public-clean.js +1063 -0
- package/contracts/deploy/deploy-public-contract.js +1107 -0
- package/contracts/deployment.config.example.js +25 -0
- package/contracts/remix-compile.js +222 -0
- package/contracts/setup-deployment.js +51 -0
- package/contracts/src/NZIP-NFT-Private.sol +350 -0
- package/contracts/src/NZIP-NFT.sol +265 -0
- package/contracts/src/ZipFileNFT-DEPRECATED-6field.sol +260 -0
- package/contracts/src/ZipFileNFT-DEPRECATED-Enhanced.sol +289 -0
- package/dist/browser/CertificateGeneratorBrowser.d.ts +75 -0
- package/dist/browser/CertificateGeneratorBrowser.js +433 -0
- package/dist/browser/TokenVerifierBrowser.d.ts +76 -0
- package/dist/browser/TokenVerifierBrowser.js +299 -0
- package/dist/browser/ZipKitBrowser.d.ts +18 -0
- package/dist/browser/ZipKitBrowser.js +250 -0
- package/dist/browser/ZipKitStampBrowser.d.ts +2 -0
- package/dist/browser/ZipKitStampBrowser.js +12 -0
- package/dist/browser-index.d.ts +21 -0
- package/dist/browser-index.js +58 -0
- package/dist/browser.d.ts +21 -0
- package/dist/browser.js +58 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +76 -0
- package/dist/server/blockchain/CertificateToken.d.ts +48 -0
- package/dist/server/blockchain/CertificateToken.js +386 -0
- package/dist/server/blockchain/NFTMinter.d.ts +41 -0
- package/dist/server/blockchain/NFTMinter.js +323 -0
- package/dist/server/blockchain/TokenQuerier.d.ts +31 -0
- package/dist/server/blockchain/TokenQuerier.js +259 -0
- package/dist/server/blockchain/TokenVerifier.d.ts +20 -0
- package/dist/server/blockchain/TokenVerifier.js +395 -0
- package/dist/server/blockchain/WalletAnalyzer.d.ts +81 -0
- package/dist/server/blockchain/WalletAnalyzer.js +356 -0
- package/dist/server/blockchain/WalletFormatter.d.ts +39 -0
- package/dist/server/blockchain/WalletFormatter.js +196 -0
- package/dist/server/blockchain/WalletManager.d.ts +46 -0
- package/dist/server/blockchain/WalletManager.js +294 -0
- package/dist/server/blockchain/ZipMetadata.d.ts +27 -0
- package/dist/server/blockchain/ZipMetadata.js +131 -0
- package/dist/server/blockchain/ZipTokenProcessor.d.ts +44 -0
- package/dist/server/blockchain/ZipTokenProcessor.js +204 -0
- package/dist/server/blockchain/constants.d.ts +102 -0
- package/dist/server/blockchain/constants.js +968 -0
- package/dist/server/blockchain/index.d.ts +9 -0
- package/dist/server/blockchain/index.js +44 -0
- package/dist/server/blockchain/test-certificate.d.ts +8 -0
- package/dist/server/blockchain/test-certificate.js +100 -0
- package/dist/server/blockchain/types.d.ts +69 -0
- package/dist/server/blockchain/types.js +51 -0
- package/dist/server/platform/server/ZipKitServer.d.ts +105 -0
- package/dist/server/platform/server/ZipKitServer.js +437 -0
- package/dist/server/platform/servercomponents/ZipKitOTS.d.ts +91 -0
- package/dist/server/platform/servercomponents/ZipKitOTS.js +271 -0
- package/dist/shared/ZipEntry.d.ts +131 -0
- package/dist/shared/ZipEntry.js +686 -0
- package/dist/shared/ZipKit.d.ts +249 -0
- package/dist/shared/ZipKit.js +789 -0
- package/dist/shared/components/CertificateOTS.d.ts +15 -0
- package/dist/shared/components/CertificateOTS.js +116 -0
- package/dist/shared/components/FileSys.d.ts +2 -0
- package/dist/shared/components/FileSys.js +113 -0
- package/dist/shared/components/HashAccumulator.d.ts +55 -0
- package/dist/shared/components/HashAccumulator.js +100 -0
- package/dist/shared/components/Support.d.ts +63 -0
- package/dist/shared/components/Support.js +70 -0
- package/dist/shared/components/Util.d.ts +21 -0
- package/dist/shared/components/Util.js +115 -0
- package/dist/shared/components/ZipCrypto.d.ts +3 -0
- package/dist/shared/components/ZipCrypto.js +78 -0
- package/dist/shared/components/merkleTree.d.ts +66 -0
- package/dist/shared/components/merkleTree.js +136 -0
- package/dist/shared/constants/Errors.d.ts +53 -0
- package/dist/shared/constants/Errors.js +69 -0
- package/dist/shared/constants/Headers.d.ts +167 -0
- package/dist/shared/constants/Headers.js +191 -0
- package/dist/shared/types/index.d.ts +21 -0
- package/dist/shared/types/index.js +3 -0
- package/dist/shared/types.d.ts +33 -0
- package/dist/shared/types.js +8 -0
- package/dist/shared/version.d.ts +4 -0
- package/dist/shared/version.js +7 -0
- package/dist/types/index.d.ts +21 -0
- package/dist/types/index.js +3 -0
- package/examples/unzip-token.ts +488 -0
- package/examples/zip-token.ts +604 -0
- package/package.json +117 -0
- package/src/browser/CertificateGeneratorBrowser.ts +498 -0
- package/src/browser/TokenVerifierBrowser.ts +344 -0
- package/src/browser/ZipKitBrowser.ts +242 -0
- package/src/browser/ZipKitStampBrowser.ts +9 -0
- package/src/browser-index.ts +36 -0
- package/src/index.ts +48 -0
- package/src/server/blockchain/CertificateToken.ts +444 -0
- package/src/server/blockchain/NFTMinter.ts +357 -0
- package/src/server/blockchain/TokenQuerier.ts +287 -0
- package/src/server/blockchain/TokenVerifier.ts +453 -0
- package/src/server/blockchain/WalletAnalyzer.ts +397 -0
- package/src/server/blockchain/WalletFormatter.ts +206 -0
- package/src/server/blockchain/WalletManager.ts +294 -0
- package/src/server/blockchain/ZipMetadata.ts +117 -0
- package/src/server/blockchain/ZipTokenProcessor.ts +234 -0
- package/src/server/blockchain/constants.ts +969 -0
- package/src/server/blockchain/index.ts +42 -0
- package/src/server/blockchain/test-certificate.ts +137 -0
- package/src/server/blockchain/types.ts +134 -0
- package/src/server/platform/server/ZipKitServer.ts +459 -0
- package/src/server/platform/servercomponents/ZipKitOTS.ts +313 -0
- package/src/server/platform/servercomponents/opentimestamps.d.ts +23 -0
- package/src/shared/ZipEntry.ts +767 -0
- package/src/shared/ZipKit.ts +899 -0
- package/src/shared/components/CertificateOTS.ts +132 -0
- package/src/shared/components/FileSys.ts +87 -0
- package/src/shared/components/HashAccumulator.ts +113 -0
- package/src/shared/components/Support.ts +77 -0
- package/src/shared/components/Util.ts +113 -0
- package/src/shared/components/ZipCrypto.ts +91 -0
- package/src/shared/components/merkleTree.ts +162 -0
- package/src/shared/constants/Errors.ts +82 -0
- package/src/shared/constants/Headers.ts +203 -0
- package/src/shared/types/index.ts +25 -0
- package/src/shared/types/modules.d.ts +22 -0
- package/src/shared/types/opentimestamps.d.ts +23 -0
- package/src/shared/types.d.ts +8 -0
- package/src/shared/types.ts +43 -0
- package/src/shared/version.ts +4 -0
- package/src/types/index.ts +25 -0
- package/src/types/modules.d.ts +22 -0
- package/src/types/opentimestamps.d.ts +23 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for Merkle tree construction
|
|
5
|
+
*/
|
|
6
|
+
interface MerkleTreeOptions {
|
|
7
|
+
hashLeaves: boolean; // Whether to hash the leaf nodes before adding to tree
|
|
8
|
+
sortLeaves: boolean; // Whether to sort leaf nodes for consistent trees
|
|
9
|
+
sortPairs: boolean; // Whether to sort each pair before hashing
|
|
10
|
+
duplicateOdd: boolean; // Whether to duplicate last leaf when odd number of leaves
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Implementation of a Merkle Tree (hash tree) using SHA-256
|
|
15
|
+
*
|
|
16
|
+
* A Merkle tree is a binary tree where each non-leaf node is the hash of its two children.
|
|
17
|
+
* This allows efficient verification of large datasets by only storing/transmitting the root hash
|
|
18
|
+
* and generating proofs of inclusion for individual items.
|
|
19
|
+
*/
|
|
20
|
+
export class MerkleTree {
|
|
21
|
+
private leaves: Buffer[]; // Leaf nodes (original data or hashes)
|
|
22
|
+
private layers: Buffer[][]; // All layers of the tree, from leaves to root
|
|
23
|
+
private options: MerkleTreeOptions;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new Merkle tree from an array of leaf nodes
|
|
27
|
+
* @param leaves - Array of leaf node data as Buffers
|
|
28
|
+
* @param options - Configuration options for tree construction
|
|
29
|
+
*/
|
|
30
|
+
constructor(leaves: Buffer[], options: Partial<MerkleTreeOptions> = {}) {
|
|
31
|
+
this.options = {
|
|
32
|
+
hashLeaves: false,
|
|
33
|
+
sortLeaves: true,
|
|
34
|
+
sortPairs: true,
|
|
35
|
+
duplicateOdd: true,
|
|
36
|
+
...options
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Process leaves according to options
|
|
40
|
+
this.leaves = leaves.map(leaf => {
|
|
41
|
+
if (this.options.hashLeaves) {
|
|
42
|
+
return this.hash(leaf);
|
|
43
|
+
}
|
|
44
|
+
return Buffer.isBuffer(leaf) ? leaf : Buffer.from(leaf);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (this.options.sortLeaves) {
|
|
48
|
+
this.leaves.sort(Buffer.compare);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
this.layers = [this.leaves];
|
|
52
|
+
this.createHashes(this.leaves);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Computes SHA-256 hash of input data
|
|
57
|
+
* @param data - Data to hash
|
|
58
|
+
* @returns Buffer containing hash
|
|
59
|
+
*/
|
|
60
|
+
private hash(data: Buffer): Buffer {
|
|
61
|
+
return createHash('sha256').update(data).digest();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Combines two child hashes to create parent hash
|
|
66
|
+
* @param left - Left child hash
|
|
67
|
+
* @param right - Right child hash
|
|
68
|
+
* @returns Combined hash of children
|
|
69
|
+
*/
|
|
70
|
+
private combinedHash(left: Buffer, right: Buffer): Buffer {
|
|
71
|
+
if (this.options.sortPairs && Buffer.compare(left, right) > 0) {
|
|
72
|
+
[left, right] = [right, left];
|
|
73
|
+
}
|
|
74
|
+
return this.hash(Buffer.concat([left, right]));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Builds the Merkle tree by creating successive layers of hashes
|
|
79
|
+
* @param nodes - Array of nodes in current layer
|
|
80
|
+
*/
|
|
81
|
+
private createHashes(nodes: Buffer[]) {
|
|
82
|
+
while (nodes.length > 1) {
|
|
83
|
+
const layerIndex = this.layers.length;
|
|
84
|
+
this.layers.push([]);
|
|
85
|
+
|
|
86
|
+
// Process pairs of nodes
|
|
87
|
+
for (let i = 0; i < nodes.length - 1; i += 2) {
|
|
88
|
+
const left = nodes[i];
|
|
89
|
+
const right = nodes[i + 1];
|
|
90
|
+
const hash = this.combinedHash(left, right);
|
|
91
|
+
this.layers[layerIndex].push(hash);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Handle odd number of nodes
|
|
95
|
+
if (nodes.length % 2 === 1) {
|
|
96
|
+
const last = nodes[nodes.length - 1];
|
|
97
|
+
if (this.options.duplicateOdd) {
|
|
98
|
+
// Duplicate the last node if odd
|
|
99
|
+
const hash = this.combinedHash(last, last);
|
|
100
|
+
this.layers[layerIndex].push(hash);
|
|
101
|
+
} else {
|
|
102
|
+
// Push last node up to next layer
|
|
103
|
+
this.layers[layerIndex].push(last);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
nodes = this.layers[layerIndex];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Gets the root hash of the Merkle tree
|
|
113
|
+
* @returns Buffer containing root hash
|
|
114
|
+
*/
|
|
115
|
+
public getRoot(): Buffer {
|
|
116
|
+
return this.layers[this.layers.length - 1][0];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Generates a proof of inclusion for a leaf node
|
|
121
|
+
* @param leaf - The leaf node to generate proof for
|
|
122
|
+
* @returns Array of sibling hashes needed to reconstruct root
|
|
123
|
+
* @throws Error if leaf not found in tree
|
|
124
|
+
*/
|
|
125
|
+
public getProof(leaf: Buffer): Buffer[] {
|
|
126
|
+
let index = this.leaves.findIndex(item => item.equals(leaf));
|
|
127
|
+
if (index === -1) {
|
|
128
|
+
throw new Error('Leaf not found in tree');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return this.layers.reduce((proof, layer) => {
|
|
132
|
+
if (layer.length === 1) return proof;
|
|
133
|
+
|
|
134
|
+
const pairIndex = index % 2 === 0 ? index + 1 : index - 1;
|
|
135
|
+
if (pairIndex < layer.length) {
|
|
136
|
+
proof.push(layer[pairIndex]);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
index = Math.floor(index / 2);
|
|
140
|
+
return proof;
|
|
141
|
+
}, [] as Buffer[]);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Verifies a proof of inclusion for a leaf node
|
|
146
|
+
* @param proof - Array of sibling hashes from getProof()
|
|
147
|
+
* @param targetHash - Hash of the leaf node being verified
|
|
148
|
+
* @param root - Expected root hash
|
|
149
|
+
* @returns boolean indicating if proof is valid
|
|
150
|
+
*/
|
|
151
|
+
public verify(proof: Buffer[], targetHash: Buffer, root: Buffer): boolean {
|
|
152
|
+
let computedHash = targetHash;
|
|
153
|
+
|
|
154
|
+
for (const proofElement of proof) {
|
|
155
|
+
computedHash = Buffer.compare(computedHash, proofElement) <= 0
|
|
156
|
+
? this.combinedHash(computedHash, proofElement)
|
|
157
|
+
: this.combinedHash(proofElement, computedHash);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return computedHash.equals(root);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// ======================================
|
|
2
|
+
// Errors.ts
|
|
3
|
+
// Copyright (c) 2024 NeoWare, Inc. All rights reserved.
|
|
4
|
+
// ======================================
|
|
5
|
+
// Error messages
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
/* Header error messages */
|
|
9
|
+
INVALID_LOC: "Invalid LOC header (bad signature)",
|
|
10
|
+
INVALID_CEN: "Invalid CEN header (bad signature)",
|
|
11
|
+
INVALID_END: "Invalid END header (bad signature)",
|
|
12
|
+
|
|
13
|
+
/* ZipEntry error messages*/
|
|
14
|
+
NO_DATA: "Nothing to decompress",
|
|
15
|
+
FILE_IN_THE_WAY: "There is a file in the way: %s",
|
|
16
|
+
UNKNOWN_METHOD: "Invalid/unsupported compression method",
|
|
17
|
+
|
|
18
|
+
/* Encryption Errors */
|
|
19
|
+
STRONG_ENCRYPT_UNSUPPORTED: "Strong Encryption is not supported",
|
|
20
|
+
|
|
21
|
+
/* Timestamp error messages */
|
|
22
|
+
INVALID_TIMESTAMP: "Invalid timestamp",
|
|
23
|
+
TIMESTAMP_FAILED: "Failed to create the timestamp",
|
|
24
|
+
|
|
25
|
+
/* Inflater error messages */
|
|
26
|
+
AVAIL_DATA: "inflate::Available inflate data did not terminate",
|
|
27
|
+
INVALID_DISTANCE: "inflate::Invalid literal/length or distance code in fixed or dynamic block",
|
|
28
|
+
TO_MANY_CODES: "inflate::Dynamic block code description: too many length or distance codes",
|
|
29
|
+
INVALID_REPEAT_LEN: "inflate::Dynamic block code description: repeat more than specified lengths",
|
|
30
|
+
INVALID_REPEAT_FIRST: "inflate::Dynamic block code description: repeat lengths with no first length",
|
|
31
|
+
INCOMPLETE_CODES: "inflate::Dynamic block code description: code lengths codes incomplete",
|
|
32
|
+
INVALID_DYN_DISTANCE: "inflate::Dynamic block code description: invalid distance code lengths",
|
|
33
|
+
INVALID_CODES_LEN: "inflate::Dynamic block code description: invalid literal/length code lengths",
|
|
34
|
+
INVALID_STORE_BLOCK: "inflate::Stored block length did not match one's complement",
|
|
35
|
+
INVALID_BLOCK_TYPE: "inflate::Invalid block type (type == 3)",
|
|
36
|
+
|
|
37
|
+
/* Extract error messages */
|
|
38
|
+
INVALID_CMP_DATA_LENGTH: "Compressed data length does not match the expected length",
|
|
39
|
+
EXTRACT_FAILED: "Failed to extract file",
|
|
40
|
+
INVALID_CRC: "CRC32 checksum does not match the expected value",
|
|
41
|
+
UNKNOWN_SHA256: "The SHA-256 hash has not been saved",
|
|
42
|
+
INVALID_SHA256: "The SHA-256 hash does not match the expected value",
|
|
43
|
+
|
|
44
|
+
/* NEO-ZIP error messages */
|
|
45
|
+
CANT_EXTRACT_FILE: "Could not extract the file",
|
|
46
|
+
CANT_OVERRIDE: "Target file already exists",
|
|
47
|
+
NO_ZIP: "No zip file was loaded",
|
|
48
|
+
NO_ENTRY: "Entry doesn't exist",
|
|
49
|
+
DIRECTORY_CONTENT_ERROR: "A directory cannot have content",
|
|
50
|
+
FILE_NOT_FOUND: "File not found: %s",
|
|
51
|
+
NOT_IMPLEMENTED: "Not implemented",
|
|
52
|
+
INVALID_FILENAME: "Invalid filename",
|
|
53
|
+
INVALID_FORMAT: "Invalid or unsupported zip format. No END header found",
|
|
54
|
+
|
|
55
|
+
// NeoZipKit error messages
|
|
56
|
+
NO_STREAM_SUPPORT: "Streams are not supported in this environment",
|
|
57
|
+
NO_BLOB_SUPPORT: "Blobs are not supported in this environment",
|
|
58
|
+
NO_FILE_READER_SUPPORT: "FileReader is not supported in this environment",
|
|
59
|
+
|
|
60
|
+
// Create Zip error messages
|
|
61
|
+
NO_FILES: "No files added, Zip file not created",
|
|
62
|
+
|
|
63
|
+
DATATYPE_STRING_UNSUPPORTED: "The String type is not supported by this platform.",
|
|
64
|
+
DATATYPE_ARRAY_UNSUPPORTED: "The Array type is not supported by this platform.",
|
|
65
|
+
DATATYPE_BUFFER_UNSUPPORTED: "The Buffer type is not supported by this platform.",
|
|
66
|
+
DATATYPE_BLOB_UNSUPPORTED: "The Blob type is not supported by this platform.",
|
|
67
|
+
DATATYPE_U8ARRAY_UNSUPPORTED: "The uint8Array type is not supported by this platform.",
|
|
68
|
+
DATATYPE_ARRAYBUFFER_UNSUPPORTED: "The ArrayBuffer type is not supported by this platform.",
|
|
69
|
+
DATATYPE_UNSUPPORTED: "Unsupported input type.",
|
|
70
|
+
|
|
71
|
+
COMPRESS_FAILED: 'Failed to compress data',
|
|
72
|
+
COMPRESSION_ERROR: 'Error occurred during compression',
|
|
73
|
+
DECOMPRESSION_ERROR: 'Error occurred during decompression',
|
|
74
|
+
|
|
75
|
+
ENCRYPT_FAILED: 'Encryption failed',
|
|
76
|
+
|
|
77
|
+
// Certificate error messages
|
|
78
|
+
CERTIFICATE_OTS_BAD: 'Unable to create OTS certificate, bad OTS timestamp',
|
|
79
|
+
CERTIFICATE_OTS_FAILED: 'Failed to create OTS certificate',
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// ======================================
|
|
2
|
+
// Headers.ts
|
|
3
|
+
// Copyright (c) 2024 NeoWare, Inc. All rights reserved.
|
|
4
|
+
// ======================================
|
|
5
|
+
// Zip File Format Constants
|
|
6
|
+
|
|
7
|
+
export const LOCAL_FILE_HEADER = 'PK\x03\x04';
|
|
8
|
+
export const CENTRAL_FILE_HEADER = 'PK\x01\x02';
|
|
9
|
+
export const CENTRAL_DIRECTORY_END = 'PK\x05\x06';
|
|
10
|
+
export const ZIP64_CENTRAL_DIRECTORY_LOCATOR = 'PK\x06\x07';
|
|
11
|
+
export const ZIP64_CENTRAL_DIRECTORY_END = 'PK\x06\x06';
|
|
12
|
+
export const DATA_DESCRIPTOR = 'PK\x07\x08';
|
|
13
|
+
|
|
14
|
+
export const TIMESTAMP_SUBMITTED = 'META-INF/TS-SUBMIT.OTS';
|
|
15
|
+
export const TIMESTAMP_METADATA = 'META-INF/TIMESTAMP.OTS';
|
|
16
|
+
export const TOKENIZED_METADATA = 'META-INF/NZIP.TOKEN';
|
|
17
|
+
|
|
18
|
+
// Local file header
|
|
19
|
+
export const LOCAL_HDR = {
|
|
20
|
+
SIZE: 30, // LOC header size in bytes
|
|
21
|
+
SIGNATURE: 0x04034b50, // "PK\003\004"
|
|
22
|
+
VER_EXTRACT: 4, // version needed to extract
|
|
23
|
+
FLAGS: 6, // general purpose bit flag
|
|
24
|
+
COMPRESSION: 8, // compression method
|
|
25
|
+
TIMEDATE_DOS: 10, // modification time (2 bytes time, 2 bytes date)
|
|
26
|
+
CRC: 14, // uncompressed file crc-32 value
|
|
27
|
+
CMP_SIZE: 18, // compressed size
|
|
28
|
+
UNCMP_SIZE: 22, // uncompressed size
|
|
29
|
+
FNAME_LEN: 26, // filename length
|
|
30
|
+
EXTRA_LEN: 28 // extra field length
|
|
31
|
+
};
|
|
32
|
+
export const ENCRYPT_HDR_SIZE = 12;
|
|
33
|
+
|
|
34
|
+
// Data descriptor
|
|
35
|
+
export const DATA_DESC = {
|
|
36
|
+
SIGNATURE: 0x08074b50, // "PK\007\008"
|
|
37
|
+
SIZE: 16, // EXT header size in bytes
|
|
38
|
+
CRC: 4, // uncompressed file crc-32 value (offset)
|
|
39
|
+
CMP_SIZE: 8, // compressed size (offset)
|
|
40
|
+
UNCMP_SIZE: 12 // uncompressed size
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// The central directory file header
|
|
44
|
+
export const CENTRAL_DIR = {
|
|
45
|
+
SIZE: 46, // Central directory header size
|
|
46
|
+
SIGNATURE: 0x02014b50, // "PK\001\002"
|
|
47
|
+
VER_MADE: 4, // version made by
|
|
48
|
+
VER_EXT: 6, // version needed to extract
|
|
49
|
+
FLAGS: 8, // encrypt, decrypt flags
|
|
50
|
+
CMP_METHOD: 10, // compression method
|
|
51
|
+
TIMEDATE_DOS: 12, // DOS modification time (2 bytes time, 2 bytes date)
|
|
52
|
+
CRC: 16, // uncompressed file crc-32 value
|
|
53
|
+
CMP_SIZE: 20, // compressed size
|
|
54
|
+
UNCMP_SIZE: 24, // uncompressed size
|
|
55
|
+
FNAME_LEN: 28, // filename length
|
|
56
|
+
EXTRA_LEN: 30, // extra field length
|
|
57
|
+
COMMENT_LEN: 32, // file comment length
|
|
58
|
+
DISK_NUM: 34, // volume number start
|
|
59
|
+
INT_FILE_ATTR: 36, // internal file attributes
|
|
60
|
+
EXT_FILE_ATTR: 38, // external file attributes (host system dependent)
|
|
61
|
+
LOCAL_HDR_OFFSET: 42 // LOC header offset
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// The Zip central directory Locator
|
|
65
|
+
export const CENTRAL_END = {
|
|
66
|
+
SIZE: 22, // END header size
|
|
67
|
+
SIGNATURE: 0x06054b50, // "PK\005\006"
|
|
68
|
+
VOL_NUM: 4, // number of this disk
|
|
69
|
+
VOLDIR_START: 6, // number of the volume/disk with start of the Central Directory
|
|
70
|
+
VOL_ENTRIES: 8, // number of entries on this volume/disk
|
|
71
|
+
TOTAL_ENTRIES: 10, // total number of entries on this disk
|
|
72
|
+
CENTRAL_DIR_SIZE: 12, // central directory size in bytes
|
|
73
|
+
CENTRAL_DIR_OFFSET: 16, // offset of first CEN header
|
|
74
|
+
ZIP_COMMENT_LEN: 20 // zip file comment length
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Zip64 Central Directory Entry
|
|
78
|
+
export const ZIP64_CENTRAL_DIR = {
|
|
79
|
+
SIGNATURE: 0x06064b50, // zip64 signature, "PK\006\006"
|
|
80
|
+
SIZE: 56, // zip64 record minimum size
|
|
81
|
+
LEAD: 12, // leading bytes at the start of the record, not counted by the value stored in ZIP64SIZE
|
|
82
|
+
SIZE_FIELD: 4, // zip64 size of the central directory record
|
|
83
|
+
VER_MADEBY: 12, // zip64 version made by
|
|
84
|
+
VER_NEEDED: 14, // zip64 version needed to extract
|
|
85
|
+
VOL_NUM: 16, // zip64 number of this disk
|
|
86
|
+
VOLDIR_START: 20, // number of the disk with the start of the record directory
|
|
87
|
+
VOL_ENTRIES: 24, // number of entries on this disk
|
|
88
|
+
TOTAL_ENTRIES: 32, // total number of entries
|
|
89
|
+
CENTRAL_DIR_SIZE: 40, // zip64 central directory size in bytes
|
|
90
|
+
CENTRAL_DIR_OFFSET: 48, // offset of start of central directory with respect to the starting disk number
|
|
91
|
+
EXTRA_FIELD: 56 // extensible data sector
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// Zip64 Central directory locator
|
|
95
|
+
export const ZIP64_CENTRAL_END = {
|
|
96
|
+
SIZE: 20, // zip64 END header size
|
|
97
|
+
SIGNATURE: 0x07064b50, // zip64 Locator signature, "PK\006\007"
|
|
98
|
+
VOL_NUM: 4, // number of the disk with the start of the zip64
|
|
99
|
+
CENTRAL_DIR_OFFSET: 8, // relative offset of the zip64 end of central directory
|
|
100
|
+
TOTAL_DISKS: 16 // total number of disks
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// Compression methods
|
|
104
|
+
export const CMP_METHOD = {
|
|
105
|
+
STORED: 0, // no compression
|
|
106
|
+
SHRUNK: 1, // shrunk
|
|
107
|
+
REDUCED1: 2, // reduced with compression factor 1
|
|
108
|
+
REDUCED2: 3, // reduced with compression factor 2
|
|
109
|
+
REDUCED3: 4, // reduced with compression factor 3
|
|
110
|
+
REDUCED4: 5, // reduced with compression factor 4
|
|
111
|
+
IMPLODED: 6, // imploded
|
|
112
|
+
DEFLATED: 8, // deflated
|
|
113
|
+
ENHANCED_DEFLATE: 9, // enhanced deflated
|
|
114
|
+
BZIP2: 12, // compressed using BZIP2
|
|
115
|
+
LZMA: 14, // LZMA
|
|
116
|
+
IBM_TERSE: 18, // compressed using IBM TERSE
|
|
117
|
+
IBM_LZ77: 19, // IBM LZ77
|
|
118
|
+
ZSTD: 93, // Zstandard compression
|
|
119
|
+
AES_ENCRYPT: 99 // WinZIP AES encryption method
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// General purpose bit flag
|
|
123
|
+
export const GP_FLAG = {
|
|
124
|
+
ENCRYPTED: 1, // Bit 0: encrypted file
|
|
125
|
+
COMPRESSION1: 2, // Bit 1, compression option
|
|
126
|
+
COMPRESSION2: 4, // Bit 2, compression option
|
|
127
|
+
DATA_DESC: 8, // Bit 3, data descriptor
|
|
128
|
+
ENHANCED_DEFLATE: 16, // Bit 4, enhanced deflating
|
|
129
|
+
PATCHED: 32, // Bit 5, indicates that the file is compressed patched data.
|
|
130
|
+
STRONG_ENCRYPT: 64, // Bit 6, strong encryption (patented)
|
|
131
|
+
// Bits 7-10: Currently unused.
|
|
132
|
+
EFS: 2048, // Bit 11: Language encoding flag (EFS)
|
|
133
|
+
// Bit 12: Reserved by PKWARE for enhanced compression.
|
|
134
|
+
// Bit 13: encrypted the Central Directory (patented).
|
|
135
|
+
// Bits 14-15: Reserved by PKWARE.
|
|
136
|
+
MASK: 4096, // mask header values
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// 4.5 Extensible data fields
|
|
140
|
+
export const EXTENSIBLE_DATA_FIELDS = {
|
|
141
|
+
ID: 0,
|
|
142
|
+
SIZE: 2,
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// Header IDs
|
|
146
|
+
export const HDR_ID = {
|
|
147
|
+
ZIP64: 0x0001,
|
|
148
|
+
AVINFO: 0x0007,
|
|
149
|
+
PFS: 0x0008,
|
|
150
|
+
OS2: 0x0009,
|
|
151
|
+
NTFS: 0x000a,
|
|
152
|
+
OPENVMS: 0x000c,
|
|
153
|
+
UNIX: 0x000d,
|
|
154
|
+
FORK: 0x000e,
|
|
155
|
+
PATCH: 0x000f,
|
|
156
|
+
x509PKCS7: 0x0014,
|
|
157
|
+
x509CERT_IDF: 0x0015,
|
|
158
|
+
x509CERT_IDC: 0x0016,
|
|
159
|
+
STRONG_ENC: 0x0017,
|
|
160
|
+
RECORD_MGT: 0x0018,
|
|
161
|
+
x509PKCS7RL: 0x0019,
|
|
162
|
+
IBM1: 0x0065,
|
|
163
|
+
IBM2: 0x0066,
|
|
164
|
+
SHA256: 0x014E, // SHA256 "N\01" with 64 bytes (256 bit) of SHA256 hash data
|
|
165
|
+
POSZIP: 0x4690, // POSZIP 4690
|
|
166
|
+
UNV_TIME: 0x5455, // Universal Time (UT) (32-bit) 5 data bytes
|
|
167
|
+
UID_GID: 0x7875, // Unix UID/GID (any size)
|
|
168
|
+
UNICODE_PATH: 0x7075, // Info-ZIP Unicode Path Extra Field
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// File System
|
|
172
|
+
export const FILE_SYSTEM = {
|
|
173
|
+
MSDOS: 0, // MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems)
|
|
174
|
+
AMIGA: 1, // Amiga
|
|
175
|
+
OPENVMS: 2, // OpenVMS
|
|
176
|
+
UNIX: 3, // UNIX
|
|
177
|
+
VM_CMS: 4, // VM/CMS
|
|
178
|
+
ATARI: 5, // Atari ST
|
|
179
|
+
OS2: 6, // OS/2 H.P.F.S.
|
|
180
|
+
MAC: 7, // Macintosh
|
|
181
|
+
CP_M: 9, // CP/M
|
|
182
|
+
NTFS: 10, // Windows NTFS
|
|
183
|
+
MVS: 11, // MVS (OS/390 - Z/OS)
|
|
184
|
+
VSE: 12, // VSE
|
|
185
|
+
ACORN: 13, // Acorn Risc
|
|
186
|
+
VFAT: 14, // VFAT
|
|
187
|
+
ALTMVS: 15, // Alternate MVS
|
|
188
|
+
BEOS: 16, // BeOS
|
|
189
|
+
TANDEM: 17, // Tandem
|
|
190
|
+
OS400: 18, // OS/400
|
|
191
|
+
DARWIN: 19 // Apple OS/X (Darwin)
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
// DOS File Attributes
|
|
195
|
+
export const DOS_FILE_ATTR = {
|
|
196
|
+
READONLY: 0x01,
|
|
197
|
+
HIDDEN: 0x02,
|
|
198
|
+
SYSTEM: 0x04,
|
|
199
|
+
VOLUME: 0x08,
|
|
200
|
+
DIRECTORY: 0x10,
|
|
201
|
+
ARCHIVE: 0x20
|
|
202
|
+
};
|
|
203
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface FileData {
|
|
2
|
+
name: string;
|
|
3
|
+
size: number;
|
|
4
|
+
lastModified: number;
|
|
5
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ZipFileEntry {
|
|
9
|
+
fileData?: FileData;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface Support {
|
|
13
|
+
base64: boolean;
|
|
14
|
+
array: boolean;
|
|
15
|
+
string: boolean;
|
|
16
|
+
isNode: boolean;
|
|
17
|
+
buffer: boolean;
|
|
18
|
+
uint8array: boolean;
|
|
19
|
+
arrayBuffer: boolean;
|
|
20
|
+
blob: boolean;
|
|
21
|
+
streams: boolean;
|
|
22
|
+
fileReader: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// External module types are handled by installed @types packages
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare module 'pako' {
|
|
2
|
+
export function deflateRaw(data: Uint8Array | Buffer, options?: any): Buffer;
|
|
3
|
+
export function inflateRaw(data: Uint8Array | Buffer): Buffer;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
declare module 'opentimestamps' {
|
|
7
|
+
export class Ops {
|
|
8
|
+
static OpSHA256: any;
|
|
9
|
+
}
|
|
10
|
+
export class DetachedTimestampFile {
|
|
11
|
+
static fromHash(op: any, digest: Buffer): DetachedTimestampFile;
|
|
12
|
+
static deserialize(ots: Buffer): DetachedTimestampFile;
|
|
13
|
+
serializeToBytes(): Uint8Array;
|
|
14
|
+
timestamp?: {
|
|
15
|
+
allAttestations(): string[];
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function stamp(detached: DetachedTimestampFile[]): Promise<void>;
|
|
19
|
+
export function upgrade(ots: DetachedTimestampFile): Promise<boolean>;
|
|
20
|
+
export function verify(ots: DetachedTimestampFile, hash: DetachedTimestampFile, options?: any): Promise<any>;
|
|
21
|
+
export function info(detached: DetachedTimestampFile): string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type declarations for OpenTimestamps module
|
|
3
|
+
*/
|
|
4
|
+
declare module 'opentimestamps' {
|
|
5
|
+
namespace stamp {
|
|
6
|
+
function create(fileBuffer: Buffer): Promise<Buffer>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
namespace verify {
|
|
10
|
+
function verifyTimestamp(ots: Buffer, fileHash: Buffer): Promise<any>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
namespace utils {
|
|
14
|
+
function hexToBytes(hex: string): number[];
|
|
15
|
+
function bytesToHex(bytes: number[]): string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default {
|
|
19
|
+
stamp,
|
|
20
|
+
verify,
|
|
21
|
+
utils
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { VERSION } from './version';
|
|
2
|
+
|
|
3
|
+
export interface FileData {
|
|
4
|
+
name: string;
|
|
5
|
+
size: number;
|
|
6
|
+
lastModified: number;
|
|
7
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface FileReader extends EventTarget {
|
|
11
|
+
readAsArrayBuffer(blob: Blob): void;
|
|
12
|
+
onload: ((this: FileReader, ev: ProgressEvent<FileReader>) => any) | null;
|
|
13
|
+
onerror: ((this: FileReader, ev: ProgressEvent<FileReader>) => any) | null;
|
|
14
|
+
result: string | ArrayBuffer | null;
|
|
15
|
+
error: Error | null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ZipFileEntry {
|
|
19
|
+
filename: string;
|
|
20
|
+
comment?: string | null;
|
|
21
|
+
fileData?: FileData;
|
|
22
|
+
fileBuffer?: Buffer | null;
|
|
23
|
+
isDirectory: boolean;
|
|
24
|
+
isMetaData: boolean;
|
|
25
|
+
isEncrypted: boolean;
|
|
26
|
+
sha256?: string | null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface AttestationValue {
|
|
30
|
+
blockHeight: number;
|
|
31
|
+
transactionId: string;
|
|
32
|
+
merkleRoot: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface NeoZipKitInfo {
|
|
36
|
+
version: string;
|
|
37
|
+
releaseDate: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const NEOZIPKIT_INFO: NeoZipKitInfo = {
|
|
41
|
+
version: VERSION.number,
|
|
42
|
+
releaseDate: VERSION.date
|
|
43
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface FileData {
|
|
2
|
+
name: string;
|
|
3
|
+
size: number;
|
|
4
|
+
lastModified: number;
|
|
5
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ZipFileEntry {
|
|
9
|
+
fileData?: FileData;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface Support {
|
|
13
|
+
base64: boolean;
|
|
14
|
+
array: boolean;
|
|
15
|
+
string: boolean;
|
|
16
|
+
isNode: boolean;
|
|
17
|
+
buffer: boolean;
|
|
18
|
+
uint8array: boolean;
|
|
19
|
+
arrayBuffer: boolean;
|
|
20
|
+
blob: boolean;
|
|
21
|
+
streams: boolean;
|
|
22
|
+
fileReader: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// External module types are handled by installed @types packages
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare module 'pako' {
|
|
2
|
+
export function deflateRaw(data: Uint8Array | Buffer, options?: any): Buffer;
|
|
3
|
+
export function inflateRaw(data: Uint8Array | Buffer): Buffer;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
declare module 'opentimestamps' {
|
|
7
|
+
export class Ops {
|
|
8
|
+
static OpSHA256: any;
|
|
9
|
+
}
|
|
10
|
+
export class DetachedTimestampFile {
|
|
11
|
+
static fromHash(op: any, digest: Buffer): DetachedTimestampFile;
|
|
12
|
+
static deserialize(ots: Buffer): DetachedTimestampFile;
|
|
13
|
+
serializeToBytes(): Uint8Array;
|
|
14
|
+
timestamp?: {
|
|
15
|
+
allAttestations(): string[];
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function stamp(detached: DetachedTimestampFile[]): Promise<void>;
|
|
19
|
+
export function upgrade(ots: DetachedTimestampFile): Promise<boolean>;
|
|
20
|
+
export function verify(ots: DetachedTimestampFile, hash: DetachedTimestampFile, options?: any): Promise<any>;
|
|
21
|
+
export function info(detached: DetachedTimestampFile): string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type declarations for OpenTimestamps module
|
|
3
|
+
*/
|
|
4
|
+
declare module 'opentimestamps' {
|
|
5
|
+
namespace stamp {
|
|
6
|
+
function create(fileBuffer: Buffer): Promise<Buffer>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
namespace verify {
|
|
10
|
+
function verifyTimestamp(ots: Buffer, fileHash: Buffer): Promise<any>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
namespace utils {
|
|
14
|
+
function hexToBytes(hex: string): number[];
|
|
15
|
+
function bytesToHex(bytes: number[]): string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default {
|
|
19
|
+
stamp,
|
|
20
|
+
verify,
|
|
21
|
+
utils
|
|
22
|
+
};
|
|
23
|
+
}
|