@turnkey/ethers
Advanced tools
Comparing version 0.4.0 to 0.5.0
# @turnkey/ethers | ||
## 0.5.0 | ||
### Minor Changes | ||
- Arbitrary message signing | ||
### Patch Changes | ||
- Updated dependencies | ||
- @turnkey/http@0.5.0 | ||
## 0.4.0 | ||
@@ -4,0 +15,0 @@ |
@@ -36,4 +36,6 @@ import { ethers } from "ethers"; | ||
private _signTransactionWithErrorWrapping; | ||
signMessage(_message: string | ethers.utils.Bytes): Promise<string>; | ||
signTransaction(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>): Promise<string>; | ||
signMessage(message: string): Promise<string>; | ||
_signMessageWithErrorWrapping(message: string): Promise<string>; | ||
_signMessageImpl(message: string): Promise<string>; | ||
} | ||
@@ -40,0 +42,0 @@ export declare function assertNonNull<T>(input: T | null | undefined): T; |
@@ -90,5 +90,2 @@ "use strict"; | ||
} | ||
async signMessage(_message) { | ||
throw new Error("Not implemented yet"); | ||
} | ||
async signTransaction(transaction) { | ||
@@ -101,2 +98,55 @@ const unsignedTx = await ethers_1.ethers.utils.resolveProperties(transaction); | ||
} | ||
async signMessage(message) { | ||
const nonHexPrefixedSerializedMessage = message.replace(/^0x/, ""); | ||
const signedMessage = await this._signMessageWithErrorWrapping(nonHexPrefixedSerializedMessage); | ||
return `${signedMessage}`; | ||
} | ||
async _signMessageWithErrorWrapping(message) { | ||
let signedMessage; | ||
try { | ||
signedMessage = await this._signMessageImpl(message); | ||
} | ||
catch (error) { | ||
if (error instanceof TurnkeyActivityError) { | ||
throw error; | ||
} | ||
throw new TurnkeyActivityError({ | ||
message: `Failed to sign`, | ||
cause: error, | ||
}); | ||
} | ||
return signedMessage; | ||
} | ||
async _signMessageImpl(message) { | ||
const { activity } = await http_1.PublicApiService.postSignRawPayload({ | ||
body: { | ||
type: "ACTIVITY_TYPE_SIGN_RAW_PAYLOAD", | ||
organizationId: this.config.organizationId, | ||
parameters: { | ||
privateKeyId: this.config.privateKeyId, | ||
payload: message, | ||
encoding: "PAYLOAD_ENCODING_TEXT_UTF8", | ||
hashFunction: "HASH_FUNCTION_KECCAK256", | ||
}, | ||
timestampMs: String(Date.now()), // millisecond timestamp | ||
}, | ||
}); | ||
const { id, status, type } = activity; | ||
if (activity.status === "ACTIVITY_STATUS_COMPLETED") { | ||
let result = assertNonNull(activity?.result?.signRawPayloadResult); | ||
let assembled = ethers_1.ethers.utils.joinSignature({ | ||
r: `0x${result.r}`, | ||
s: `0x${result.s}`, | ||
v: parseInt(result.v) + 27, | ||
}); | ||
// assemble the hex | ||
return assertNonNull(assembled); | ||
} | ||
throw new TurnkeyActivityError({ | ||
message: `Invalid activity status: ${activity.status}`, | ||
activityId: id, | ||
activityStatus: status, | ||
activityType: type, | ||
}); | ||
} | ||
} | ||
@@ -103,0 +153,0 @@ exports.TurnkeySigner = TurnkeySigner; |
{ | ||
"name": "@turnkey/ethers", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"main": "./dist/index.js", | ||
@@ -37,3 +37,3 @@ "types": "./dist/index.d.ts", | ||
"dependencies": { | ||
"@turnkey/http": "0.4.0" | ||
"@turnkey/http": "0.5.0" | ||
}, | ||
@@ -40,0 +40,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30324
205
+ Added@turnkey/http@0.5.0(transitive)
- Removed@turnkey/http@0.4.0(transitive)
Updated@turnkey/http@0.5.0