@openwallet-foundation/askar-shared 0.3.2-alpha-20250318162328 → 0.3.2
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/installBinary.js +83 -0
- package/package.json +5 -3
package/installBinary.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const tar = require('tar')
|
|
3
|
+
const fs = require('fs')
|
|
4
|
+
|
|
5
|
+
async function downloadBinaryIfNeeded({ packageName, version, host, targetDirectory }) {
|
|
6
|
+
if (!needsDownload({ version, targetDirectory })) return
|
|
7
|
+
|
|
8
|
+
await downloadBinary({ packageName, version, host, targetDirectory })
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function needsDownload({ version, targetDirectory }) {
|
|
12
|
+
const metadataPath = path.join(targetDirectory, 'version.json')
|
|
13
|
+
|
|
14
|
+
if (!fs.existsSync(metadataPath)) return true
|
|
15
|
+
|
|
16
|
+
// Check if metadata exists and matches current version
|
|
17
|
+
try {
|
|
18
|
+
const metadata = JSON.parse(fs.readFileSync(metadataPath, 'utf8'))
|
|
19
|
+
if (metadata.version === version) {
|
|
20
|
+
console.log('Binary is up to date, skipping download')
|
|
21
|
+
return false
|
|
22
|
+
}
|
|
23
|
+
} catch (error) {
|
|
24
|
+
// If metadata is corrupted, download anyway
|
|
25
|
+
console.log('Metadata file is invalid, will download binary')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return true
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function downloadBinary({ packageName, version, host, targetDirectory }) {
|
|
32
|
+
const url = `${host}/${version}/${packageName}`
|
|
33
|
+
const metadataPath = path.join(targetDirectory, 'version.json')
|
|
34
|
+
|
|
35
|
+
console.log(`Downloading binary from ${url} to \n ${targetDirectory}...`)
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
// Ensure the directory exists
|
|
39
|
+
if (!fs.existsSync(targetDirectory)) {
|
|
40
|
+
fs.mkdirSync(targetDirectory, { recursive: true })
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const response = await fetch(url)
|
|
44
|
+
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
throw new Error(`Failed to download: ${response.status} ${response.statusText}`)
|
|
47
|
+
}
|
|
48
|
+
const data = await response.arrayBuffer()
|
|
49
|
+
|
|
50
|
+
// Write the downloaded file first
|
|
51
|
+
const tempFile = path.join(targetDirectory, 'aries_askar.tar.gz')
|
|
52
|
+
fs.writeFileSync(tempFile, Buffer.from(data))
|
|
53
|
+
|
|
54
|
+
// Then extract it
|
|
55
|
+
return tar
|
|
56
|
+
.extract({
|
|
57
|
+
file: tempFile,
|
|
58
|
+
cwd: targetDirectory,
|
|
59
|
+
strip: 1,
|
|
60
|
+
})
|
|
61
|
+
.then(() => {
|
|
62
|
+
// Remove the tarball after extraction
|
|
63
|
+
fs.unlinkSync(tempFile)
|
|
64
|
+
|
|
65
|
+
// Save version metadata
|
|
66
|
+
fs.writeFileSync(
|
|
67
|
+
metadataPath,
|
|
68
|
+
JSON.stringify({
|
|
69
|
+
version,
|
|
70
|
+
})
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
console.log('Binary downloaded and extracted successfully')
|
|
74
|
+
})
|
|
75
|
+
} catch (error) {
|
|
76
|
+
console.error('Error downloading binary:', error)
|
|
77
|
+
process.exit(1)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = {
|
|
82
|
+
downloadBinaryIfNeeded,
|
|
83
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openwallet-foundation/askar-shared",
|
|
3
|
-
"version": "0.3.2
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Shared library for using Askar with NodeJS and React Native",
|
|
6
6
|
"main": "build/index",
|
|
@@ -17,10 +17,12 @@
|
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
|
-
"build"
|
|
20
|
+
"build",
|
|
21
|
+
"installBinary.js"
|
|
21
22
|
],
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"buffer": "^6.0.3"
|
|
24
|
+
"buffer": "^6.0.3",
|
|
25
|
+
"tar": "^7.4.3"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
26
28
|
"typescript": "~5.4.5"
|