2023-12-06 11:03:05 +03:00
|
|
|
// prettier-ignore
|
2023-03-27 09:59:36 +03:00
|
|
|
/* eslint-disable */
|
|
|
|
/* auto-generated by NAPI-RS */
|
|
|
|
|
|
|
|
const { existsSync, readFileSync } = require('fs')
|
2023-10-19 10:17:04 +03:00
|
|
|
const { join } = require('path')
|
2023-03-27 09:59:36 +03:00
|
|
|
|
2023-10-19 10:17:04 +03:00
|
|
|
const { platform, arch } = process
|
2023-03-27 09:59:36 +03:00
|
|
|
|
2023-10-19 10:17:04 +03:00
|
|
|
let nativeBinding = null
|
|
|
|
let localFileExisted = false
|
|
|
|
let loadError = null
|
2023-03-27 09:59:36 +03:00
|
|
|
|
2023-12-06 11:03:05 +03:00
|
|
|
const isMusl = () => {
|
|
|
|
let musl = false
|
|
|
|
if (process.platform === 'linux') {
|
|
|
|
musl = isMuslFromFilesystem()
|
|
|
|
if (musl === null) {
|
|
|
|
musl = isMuslFromReport()
|
|
|
|
}
|
|
|
|
if (musl === null) {
|
|
|
|
musl = isMuslFromChildProcess()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return musl
|
|
|
|
}
|
|
|
|
|
|
|
|
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
|
|
|
|
|
|
|
|
const isMuslFromFilesystem = () => {
|
|
|
|
try {
|
|
|
|
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
|
|
|
|
} catch {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const isMuslFromReport = () => {
|
|
|
|
const report = typeof process.report.getReport === 'function' ? process.report.getReport() : null
|
|
|
|
if (!report) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
if (report.header && report.header.glibcVersionRuntime) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (Array.isArray(report.sharedObjects)) {
|
|
|
|
if (report.sharedObjects.some(isFileMusl)) {
|
2023-10-19 10:17:04 +03:00
|
|
|
return true
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-12-06 11:03:05 +03:00
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
const isMuslFromChildProcess = () => {
|
|
|
|
try {
|
|
|
|
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
|
|
|
} catch (e) {
|
|
|
|
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
|
|
|
return false
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (platform) {
|
|
|
|
case 'android':
|
|
|
|
switch (arch) {
|
|
|
|
case 'arm64':
|
2023-10-19 10:17:04 +03:00
|
|
|
localFileExisted = existsSync(join(__dirname, 'affine.android-arm64.node'))
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.android-arm64.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-android-arm64')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
case 'arm':
|
2023-10-19 10:17:04 +03:00
|
|
|
localFileExisted = existsSync(join(__dirname, 'affine.android-arm-eabi.node'))
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.android-arm-eabi.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-android-arm-eabi')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
default:
|
2023-10-19 10:17:04 +03:00
|
|
|
throw new Error(`Unsupported architecture on Android ${arch}`)
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
case 'win32':
|
|
|
|
switch (arch) {
|
|
|
|
case 'x64':
|
|
|
|
localFileExisted = existsSync(
|
2023-05-10 12:16:48 +03:00
|
|
|
join(__dirname, 'affine.win32-x64-msvc.node')
|
2023-10-19 10:17:04 +03:00
|
|
|
)
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.win32-x64-msvc.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-win32-x64-msvc')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
case 'ia32':
|
|
|
|
localFileExisted = existsSync(
|
2023-05-10 12:16:48 +03:00
|
|
|
join(__dirname, 'affine.win32-ia32-msvc.node')
|
2023-10-19 10:17:04 +03:00
|
|
|
)
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.win32-ia32-msvc.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-win32-ia32-msvc')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
case 'arm64':
|
|
|
|
localFileExisted = existsSync(
|
2023-05-10 12:16:48 +03:00
|
|
|
join(__dirname, 'affine.win32-arm64-msvc.node')
|
2023-10-19 10:17:04 +03:00
|
|
|
)
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.win32-arm64-msvc.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-win32-arm64-msvc')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
default:
|
2023-10-19 10:17:04 +03:00
|
|
|
throw new Error(`Unsupported architecture on Windows: ${arch}`)
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
case 'darwin':
|
2023-10-19 10:17:04 +03:00
|
|
|
localFileExisted = existsSync(join(__dirname, 'affine.darwin-universal.node'))
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.darwin-universal.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-darwin-universal')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
} catch {}
|
|
|
|
switch (arch) {
|
|
|
|
case 'x64':
|
2023-10-19 10:17:04 +03:00
|
|
|
localFileExisted = existsSync(join(__dirname, 'affine.darwin-x64.node'))
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.darwin-x64.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-darwin-x64')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
case 'arm64':
|
|
|
|
localFileExisted = existsSync(
|
2023-05-10 12:16:48 +03:00
|
|
|
join(__dirname, 'affine.darwin-arm64.node')
|
2023-10-19 10:17:04 +03:00
|
|
|
)
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.darwin-arm64.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-darwin-arm64')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
default:
|
2023-10-19 10:17:04 +03:00
|
|
|
throw new Error(`Unsupported architecture on macOS: ${arch}`)
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
case 'freebsd':
|
|
|
|
if (arch !== 'x64') {
|
2023-10-19 10:17:04 +03:00
|
|
|
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
localFileExisted = existsSync(join(__dirname, 'affine.freebsd-x64.node'))
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.freebsd-x64.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-freebsd-x64')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
case 'linux':
|
|
|
|
switch (arch) {
|
|
|
|
case 'x64':
|
|
|
|
if (isMusl()) {
|
|
|
|
localFileExisted = existsSync(
|
2023-05-10 12:16:48 +03:00
|
|
|
join(__dirname, 'affine.linux-x64-musl.node')
|
2023-10-19 10:17:04 +03:00
|
|
|
)
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.linux-x64-musl.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-linux-x64-musl')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
localFileExisted = existsSync(
|
2023-05-10 12:16:48 +03:00
|
|
|
join(__dirname, 'affine.linux-x64-gnu.node')
|
2023-10-19 10:17:04 +03:00
|
|
|
)
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.linux-x64-gnu.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-linux-x64-gnu')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
case 'arm64':
|
|
|
|
if (isMusl()) {
|
|
|
|
localFileExisted = existsSync(
|
2023-05-10 12:16:48 +03:00
|
|
|
join(__dirname, 'affine.linux-arm64-musl.node')
|
2023-10-19 10:17:04 +03:00
|
|
|
)
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.linux-arm64-musl.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-linux-arm64-musl')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
localFileExisted = existsSync(
|
2023-05-10 12:16:48 +03:00
|
|
|
join(__dirname, 'affine.linux-arm64-gnu.node')
|
2023-10-19 10:17:04 +03:00
|
|
|
)
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.linux-arm64-gnu.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-linux-arm64-gnu')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
case 'arm':
|
|
|
|
localFileExisted = existsSync(
|
2023-05-10 12:16:48 +03:00
|
|
|
join(__dirname, 'affine.linux-arm-gnueabihf.node')
|
2023-10-19 10:17:04 +03:00
|
|
|
)
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.linux-arm-gnueabihf.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-linux-arm-gnueabihf')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
default:
|
2023-10-19 10:17:04 +03:00
|
|
|
throw new Error(`Unsupported architecture on Linux: ${arch}`)
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
default:
|
2023-10-19 10:17:04 +03:00
|
|
|
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!nativeBinding) {
|
|
|
|
if (loadError) {
|
2023-10-19 10:17:04 +03:00
|
|
|
throw loadError
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
throw new Error(`Failed to load native binding`)
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
|
2023-12-06 11:03:05 +03:00
|
|
|
module.exports.SqliteConnection = nativeBinding.SqliteConnection
|
|
|
|
module.exports.mintChallengeResponse = nativeBinding.mintChallengeResponse
|
|
|
|
module.exports.ValidationResult = nativeBinding.ValidationResult
|
|
|
|
module.exports.verifyChallengeResponse = nativeBinding.verifyChallengeResponse
|