Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wax
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
wax
Merge requests
!282
Add signature providers
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add signature providers
tm-sign-ext
into
develop
Overview
0
Commits
40
Pipelines
46
Changes
9
Merged
Mateusz Tyszczak
requested to merge
tm-sign-ext
into
develop
1 month ago
Overview
0
Commits
40
Pipelines
46
Changes
9
Expand
Requires:
common-ci-configuration!75 (merged)
Edited
3 weeks ago
by
Bartek Wrona
0
0
Merge request reports
Viewing commit
84d44ec8
Show latest version
9 files
+
224
−
24
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
9
Search (e.g. *.vue) (Ctrl+P)
Verified
84d44ec8
Add signers-peakvault package
· 84d44ec8
Mateusz Tyszczak
authored
1 month ago
ts/packages/signers-peakvault/src/index.ts
0 → 100644
+
69
−
0
Options
import
type
{
IOnlineSignatureProvider
,
ITransaction
,
TAccountName
,
TRole
}
from
"
@hiveio/wax
"
;
import
{
getWallet
}
from
'
@peakd/hive-wallet-sdk
'
// @peakd/hive-wallet-sdk fails to provide this type import
type
KeyRole
=
Parameters
<
typeof
PeakVaultProvider
[
'
peakVaultWallet
'
][
'
signTx
'
]
>
[
2
];
const
mapRoles
:
Record
<
TRole
,
KeyRole
|
undefined
>
=
{
active
:
'
active
'
,
posting
:
'
posting
'
,
owner
:
undefined
,
memo
:
'
memo
'
};
const
PEAKVAULT_WALLET_ID
:
Parameters
<
typeof
getWallet
>
[
0
]
=
'
peakvault
'
;
// We do not extend from WaxError to avoid runtime dependencies, such as: /vite or /web - without it we can import only types
export
class
WaxPeakVaultProviderError
extends
Error
{}
/**
* Wax transaction signature provider using the Peak Vault.
*
* @example
* ```
* const provider = PeakVaultProvider.for("myaccount", "active");
*
* // Create a transaction using the Wax Hive chain instance
* const tx = await chain.createTransaction();
*
* // Perform some operations, e.g. pushing operations...
*
* // Sign the transaction
* await tx.sign(provider);
*
* // broadcast
* await chain.broadcast(tx);
* ```
*/
class
PeakVaultProvider
implements
IOnlineSignatureProvider
{
private
readonly
role
:
KeyRole
;
private
static
peakVaultWallet
:
Awaited
<
ReturnType
<
typeof
getWallet
>>
;
private
constructor
(
private
readonly
accountName
:
TAccountName
,
role
:
TRole
)
{
if
(
!
mapRoles
[
role
])
throw
new
Error
(
`Role
${
role
}
is not supported by the Wax signature provider:
${
PeakVaultProvider
.
name
}
`
);
this
.
role
=
mapRoles
[
role
];
}
public
static
for
(
accountName
:
TAccountName
,
role
:
TRole
):
PeakVaultProvider
{
return
new
PeakVaultProvider
(
accountName
,
role
);
}
public
async
signTransaction
(
transaction
:
ITransaction
):
Promise
<
void
>
{
if
(
!
PeakVaultProvider
.
peakVaultWallet
)
PeakVaultProvider
.
peakVaultWallet
=
await
getWallet
(
PEAKVAULT_WALLET_ID
);
const
data
=
await
PeakVaultProvider
.
peakVaultWallet
.
signTx
(
this
.
accountName
,
JSON
.
parse
(
transaction
.
toLegacyApi
()),
this
.
role
);
for
(
const
sig
of
data
.
result
.
signatures
)
transaction
.
sign
(
sig
);
}
}
export
default
PeakVaultProvider
;
Loading