Browse Source

fix: buffer typescript error in util.ts when parsing ArrayBuffer

kb/add-usage-guide
Jason Buchanan 6 months ago
parent
commit
09dccc34d6
No known key found for this signature in database GPG Key ID: 1A12361012426318
  1. 2
      package-lock.json
  2. 2
      package.json
  3. 29
      src/libs/util.ts
  4. 35
      tsconfig.json

2
package-lock.json

@ -28,7 +28,6 @@
"@vueuse/core": "^10.9.0",
"@zxing/text-encoding": "^0.9.0",
"axios": "^1.6.8",
"buffer": "^6.0.3",
"class-transformer": "^0.5.1",
"dexie": "^3.2.7",
"dexie-export-import": "^4.1.1",
@ -66,7 +65,6 @@
},
"devDependencies": {
"@types/leaflet": "^1.9.8",
"@types/node": "^20.11.30",
"@types/ramda": "^0.29.11",
"@types/three": "^0.155.1",
"@types/ua-parser-js": "^0.7.39",

2
package.json

@ -29,7 +29,6 @@
"@vueuse/core": "^10.9.0",
"@zxing/text-encoding": "^0.9.0",
"axios": "^1.6.8",
"buffer": "^6.0.3",
"class-transformer": "^0.5.1",
"dexie": "^3.2.7",
"dexie-export-import": "^4.1.1",
@ -67,7 +66,6 @@
},
"devDependencies": {
"@types/leaflet": "^1.9.8",
"@types/node": "^20.11.30",
"@types/ramda": "^0.29.11",
"@types/three": "^0.155.1",
"@types/ua-parser-js": "^0.7.39",

29
src/libs/util.ts

@ -12,8 +12,6 @@ import { deriveAddress, generateSeed, newIdentifier } from "@/libs/crypto";
import { GenericServerRecord, containsHiddenDid } from "@/libs/endorserServer";
import * as serverUtil from "@/libs/endorserServer";
import { Buffer } from "buffer/";
// If you edit this, check that the numbers still line up on the side in the alert (on mobile, too),
// and make sure they can take all actions while the notification shows.
export const ONBOARD_MESSAGE =
@ -237,6 +235,19 @@ export const generateSaveAndActivateIdentity = async (): Promise<string> => {
return newId.did;
};
function getBase64(subscription: PushSubscription, key: PushEncryptionKeyName) {
const buffer = subscription.getKey(key);
if (!buffer) {
return null;
}
const value = Buffer.from(buffer);
return value
.toString("base64")
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=+$/, "");
}
export const sendTestThroughPushServer = async (
subscription: PushSubscription,
skipFilter: boolean,
@ -253,18 +264,8 @@ export const sendTestThroughPushServer = async (
// Use something other than "Daily Update" https://gitea.anomalistdesign.com/trent_larson/py-push-server/src/commit/3c0e196c11bc98060ec5934e99e7dbd591b5da4d/app.py#L213
const DIRECT_PUSH_TITLE = "DIRECT_NOTIFICATION";
const auth = Buffer.from(subscription.getKey("auth"));
const authB64 = auth
.toString("base64")
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=+$/, "");
const p256dh = Buffer.from(subscription.getKey("p256dh"));
const p256dhB64 = p256dh
.toString("base64")
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=+$/, "");
const authB64 = getBase64(subscription, "auth");
const p256dhB64 = getBase64(subscription, "p256dh");
const newPayload = {
endpoint: subscription.endpoint,
keys: {

35
tsconfig.json

@ -1,39 +1,26 @@
{
"compilerOptions": {
"allowJs": true,
"resolveJsonModule": true,
"target": "ES2020",
"module": "ESNext",
"strict": true,
"strictPropertyInitialization": false,
"jsx": "preserve",
"moduleResolution": "bundler",
"target": "ES2020", // Latest ECMAScript features that are widely supported by modern browsers
"module": "ESNext", // Use ES modules
"strict": true, // Enable all strict type checking options
"jsx": "preserve", // Preserves JSX to be transformed by Babel or another transpiler
"moduleResolution": "node", // Use Node.js style module resolution
"experimentalDecorators": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true, // Enables compatibility with CommonJS modules for default imports
"allowSyntheticDefaultImports": true, // Allow default imports from modules with no default export
"forceConsistentCasingInFileNames": true, // Disallow inconsistently-cased references to the same file
"useDefineForClassFields": true,
"sourceMap": true,
"baseUrl": "./src",
"types": [
"node"
],
"baseUrl": "./src", // Base directory to resolve non-relative module names
"paths": {
"@/components/*": ["components/*"],
"@/views/*": ["views/*"],
"@/db/*": ["db/*"],
"@/libs/*": ["libs/*"],
"@/constants/*": ["constants/*"],
"@/store/*": ["store/*"],
"@/store/*": ["store/*"]
},
"lib": [
"esnext",
"es2020",
"dom",
"dom.iterable",
"scripthost"
]
"lib": ["ES2020", "dom", "dom.iterable"], // Include typings for ES2020 and DOM APIs
},
"include": [
"src/**/*.ts",

Loading…
Cancel
Save