Skip to content

Commit

Permalink
fix: support legacy encryption tags
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrvis committed Nov 8, 2023
1 parent affb10a commit 531c478
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ export enum encryptionTags {
PUBLIC_ADDRESS = "Public-Address"
};

export enum encryptionTagsLegacy {
IV = "IV",
ENCRYPTED_KEY = "EncryptedKey",
PUBLIC_ADDRESS = "Public-Address"
};

export enum smartweaveTags {
APP_NAME = "App-Name",
APP_VERSION = "App-Version",
Expand Down
10 changes: 6 additions & 4 deletions src/core/membership.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { actionRefs, objectType, status, functions, protocolTags, encryptionTags } from "../constants";
import { actionRefs, objectType, status, functions, protocolTags, encryptionTags, encryptionTagsLegacy } from "../constants";
import { v4 as uuidv4 } from "uuid";
import { EncryptedKeys, Encrypter, deriveAddress, base64ToArray, generateKeyPair, Keys, PROXY_DOWNLOAD_URL, arrayToDataUrl } from "@akord/crypto";
import { Service } from "./service";
Expand Down Expand Up @@ -418,11 +418,13 @@ class MembershipService extends Service {
type: 'init',
id: uri,
url: url
} as Record<string, any>;
} as Record<string, any>;
if (!membership.__public__) {
const tags = await this.api.getTransactionTags(uri);
const encryptedKey = tags.find(tag => tag.name.toLowerCase() === encryptionTags.ENCRYPTED_KEY.toLowerCase())?.value
const iv = tags.find(tag => tag.name.toLowerCase() === encryptionTags.IV.toLowerCase())?.value
const encryptedKey = tags.find(tag => tag.name.toLowerCase() === encryptionTags.ENCRYPTED_KEY.toLowerCase()
|| tag.name.toLowerCase() === encryptionTagsLegacy.ENCRYPTED_KEY.toLowerCase())?.value
const iv = tags.find(tag => tag.name === encryptionTags.IV
|| tag.name.toLowerCase() === encryptionTagsLegacy.IV.toLowerCase())?.value
if (encryptedKey) {
workerMessage.key = await service.dataEncrypter.decryptKey(encryptedKey);
}
Expand Down
8 changes: 5 additions & 3 deletions src/core/stack.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NodeService } from "./node";
import { actionRefs, encryptionTags, functions, objectType } from "../constants";
import { actionRefs, encryptionTags, encryptionTagsLegacy, functions, objectType } from "../constants";
import { FileDownloadOptions, FileGetOptions, FileService, FileUploadOptions, FileVersionData, createFileLike } from "./file";
import { FileSource } from "../types/file";
import { FileVersion, NodeCreateOptions, Stack, StackCreateOptions, StackCreateResult, StackUpdateResult, StorageType, nodeType } from "../types";
Expand Down Expand Up @@ -188,8 +188,10 @@ class StackService extends NodeService<Stack> {
if (!service.isPublic) {
await version.decrypt();
const tags = await this.api.getTransactionTags(id);
const encryptedKey = tags.find(tag => tag.name.toLowerCase() === encryptionTags.ENCRYPTED_KEY.toLowerCase())?.value
const iv = tags.find(tag => tag.name === encryptionTags.IV)?.value
const encryptedKey = tags.find(tag => tag.name.toLowerCase() === encryptionTags.ENCRYPTED_KEY.toLowerCase()
|| tag.name.toLowerCase() === encryptionTagsLegacy.ENCRYPTED_KEY.toLowerCase())?.value
const iv = tags.find(tag => tag.name === encryptionTags.IV
|| tag.name.toLowerCase() === encryptionTagsLegacy.IV.toLowerCase())?.value
const key = await service.dataEncrypter.decryptKey(encryptedKey);
workerMessage.key = key;
workerMessage.iv = iv;
Expand Down

0 comments on commit 531c478

Please sign in to comment.